How To Add Database Forms To A Web Page - Django Wednesdays #7
ฝัง
- เผยแพร่เมื่อ 8 มิ.ย. 2024
- In this video I'll show you how to add forms to your webpage that allow you to update your database.
Adding Database Web Forms is pretty straight forward with Django. But styling them is not! In this video we'll add a web form to our web page that allows us to add Venus to our Venue Model.
We'll also style the web form using Bootstrap to make it look nicer.
Timecodes
0:00 - Introduction
2:15 - Create Forms.py File
3:43 - Create VenueForm Form
6:20 - Create Add_Venue.html Page
7:09 - Add Path For Add_Venue Page
7:36 - Create an Add_Venue View
8:55 - Create Link on Navbar To Add_Venue Page
9:44 - Add Form To Add_Venue Page
11:57 - Add VenueForm To Views.py File
12:38 - Create Form Functionality In Views.py
15:16 - Add HttpResponseRedirect To views.py
18:57 - Add Submitted Logic To Add_Venue Web Page
20:13 - Test The Form
21:36 - Style The Form With Bootstrap
23:43 - Remove or Change Django Form Labels
25:33 - Add Placeholder Text To Form Input Fields
26:48 - Conclusion
▶️ Watch Entire Django Wednesdays Playlist ✅ Subscribe To My TH-cam Channel:
bit.ly/35Xo9jD bit.ly/2IGzvOR
▶️ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
▶️ Get The Code
bit.ly/3sJpeV6
@4: 40 A meta class is an inner class that provides a metadata about the outer class in Django, it define things such as available permissions, associated database table names, singular and plural versions of the name etc.
Thanks for the video, it was really helpful.
Best video for new learner. I watched at least 5 different people's video, most don't describe the logic or tell the thing they are doing. But he explains every single steps which is great for person who are new to coding.
Glad you enjoyed it!
after stucking for so long, and then watched your video, I have finally get the solution. TQVM. Subscribed
Glad I could help
All your classes are at next level.. hats off.. love from india
Thanks!
Your video helped me a lot to understand forms in the minimum time! Thank you so much for the great job
Happy to help!
1000th Like is Mine !!!!
Awesome!
You are one of the best teacher in the world love from india
Thank you!
Thnaks man...You always have what i need
Thank you for the video. It was very helpful.
Very welcome!
Tried FastAPI, Flask and now Django.... Loving Django. It makes so much sense. Good tutorial. Thanks
Glad you like em!
Thank you!!, this video was very helpful.
Glad you liked it!
wow .This video helps me a lot in understanding forms in django. I have read the django doc but your video helps me a lots . Moreover your teaching skill is amazing
Glad you're enjoying it!
Thanks for the video, it was very helpful in learning django!
Happy to hear it!
Hi. Great course. I like to listening very much. I learned a lot from you. Have you thought about doing a course on how to use datapicker in record editing forms? I have a model-based form.
I have working code that adds a record. I use the same form for editing, but unfortunately it does not retrieve the current record data. I have to enter a new date when editing.
I was also thinking about using the datapicker with admin.
There are a lot of tutorials on stackoverflow - I've tried a few of them but they didn't work for me :)
great explanation !
Thanks!
Thank you very much, Heisenberg
lol
sooooo good video very useful thanks
Welcome!
Hey this project is amazing. Plz finish this peoject ASAP....i cant wait!
Thanks! New video every Wednesday
I am trying to add a place holder to a Form.select field for a combo dropdown box. I am wondering if you have any easy references for how to use the place holder in a combo box. Thanks
hello, when i submit the form i get submitted = True but it wont return your venue addded succesfully why
I love you man!
Thanks!
thank you
Welcome!
How can I use textarea to take input for one of the table in django
How could I print out what Venue was created in the /add_venue?submitted=True?
How do you do to have a label for the primary key of the class?
I'd like to add an author for the form, where the author being the logged in user themselves. How do I do It?
Thank you very much for the video I had two questions: the first is how can I make it so that the saved information is saved and only viewable by the user account that created it (I say this because I have made a registration and login system with authentication of a password manager web app and therefore it would be inconsistent to see the passwords of all)
the second: if this information saved on the database I want it to also be viewable on an html page organised in rows/columns, how can I do this? and if so whether there is a possibility from the html page to delete a saved password (via a button) instead of doing it from the django administration.
your questions are all answered in the videos
Thanks !!!!!
Welcome!
thank you very much .you help us to create our project.... !!! could you make video about ecommerce
Happy to hear it!
Hi John, GREAT COURSE....
I get a error message when i try to add the form (12:27). The error message starts with ValueError at /add_venue
ModelForm has no model class specified.
And below: Error during template rendering
In template C:\PY_Projects\myclub\myclub_website\events\templates\events\base.html, error at line 0.
Do you know what this could be? I have (double) checked the code but could not find any errors....
Much appreciated!!
ALready got it :)..... Missed a line :(
@@eduardjogi Yeah was gonna suggest putting is aside for a few hours and checking it again with fresh eyes
@@eduardjogi I got the same problem. What line?
@@flavius2884 Hi David, I cant remember it anymore. I would advice you to look at the vid again and pause every time John add something to the files. Another option is to take a look at his files at his github.
Good luck :)
what if i use namespace:name, how can i add "?submitted=True" ?
i have error "Path not found"
22:10 How can I add a class to all form fields (same as "__all__" in fields variable)? Let's say I have 40 fields, it is so inconvienient to adding all of them.
Correct by adding "__all__" you should be able to add all the fields, The idea of doing it Manually is for you to see that is not Necessary to add all if you have field that are not mandatory and you don't need them hope this help.
thank sir
welcome
second chapter, line 2 on models.py "from django.forms import ModelForm":
Is this line necessary or can this definition/class be inherited by forms.ModelForm? sry for my bad english :)
Yes, it's necessary
can you help me why in my forms.py the bootstrap wont activate
But what about auto-increment id columns? I got `Cannot insert explicit value for identity column in table 'xyz' when IDENTITY_INSERT is set to OFF. (544) (SQLExecDirectW)")` error all the Internet redirects me to my database setting, whereas I want to fix my Django app.
Django auto increments id columns automatically.
how to add 2+venues or events at once in form of table
when adding venue i do not get the page added sucessfully redirect but it does add it to the database
what did you do differently from the video?
@@Codemycom same here so right now I'm still checking but I can see it in the web browser '/add_venue?submitted = True'
Thanks for best video. Can you tutorial style label djangoform ? Thank you !!!
Yeah, I have videos on that
@@Codemycom ya, I think we need to do this without bootstrap, I want to learn basically ! Thank you :D
@@HuyNguyen-xp4ro What's the difference? Nothing I'm showing requires the use of Bootstrap, it's just easier that way. No one reinvents the wheel
at 18:39 how can line 20 ever be accessed?
i want to show how html redirecting part is working? Whict is the other vedio that you have shown this
Sorry, don't know what you mean.
Hello first comment
Yes
Awesome
thanks a lot... I have one problem the data was successfully stored in db... but the done message automatically disappeared suddenly ... what can i do...
please reply me... i am stuck in this problem
what did you do differently from the video?
class Meta allows you to edit the metadata......cheers!
lol yeah
Hey, i watched your first video and did all the steps you did in the video. But when i ran "python manage.py runserver" at last it is showing an error : "No module named app_name" . What can i do?
You either don't have your virtual environment turned on, or you aren't in the right directory in the terminal. When you type the command: ls do you see manage.py file listed?
@@Codemycom yes when i ran ls command it showed manage.py and at the above it show the name of virtual environment
in fact i tried doing the whole thing without virtual env but still faced same error
@@vikasmaur7947 Well yeah, it wouldn't work without the virtual environment. You might have to delete it all and start over...you missed a step somewhere.
@@Codemycom okay i'll try doing that
Thanks
Hey! I actually figured out what the problem was.
Actually i had written "name_of_app/urls" in the views.py file but when i saw the tutorial again i found that it was "name_of_app.urls" and when i corrected that
it ran successfully.
Thank you very much john.
You make awesome tutorials .
I really love watching you.
Good day sir, please what's the best way to store phone number in Django models ?
Probably just as characters
This doesnt seem to work in Django 5. I have watched the video several times and cannot see any errors in my code. Did anyone get this to work with Django 5?
Of course it works with Django 5
@@Codemycom Yes, sir. I will keep digging. You have great a channel, btw.
didn't return an HttpResponse object.
Is this going to be part of ur Codemy courses?
No, this is just on youtube
@@Codemycom
OK
I bought ur courses last month
Just want to know if some videos here are included there...
@@bahdev1324 Generally speaking, the paid courses are not free on TH-cam...that's why they're paid.
@@Codemycom
Okay sir thank you...
Please include hashing in this video series
Not really likely, but you never know.
How do you prevent user from going back to same form by pressing back button?
The browser handles that
Hi! Do you have the code in Github?
github.com/flatplanet/djangoblog
hello plz make a video for login and registration by using forms.py files
Yeah will probably get to that
Sir pls do followers and following system
we'll see
The output looks different for me but I wrote the same code is there any reason
sir I can't display the message. Could you help me?
Just rewatch the video and discover what you did differently from the videos. I show you everything you need.
@@Codemycom 😀Thank you sir
hello third comment
Awesome
I wish he would increase the screensize so we can see all of the code and not just roughly 50char length
code is in the pinned comment champ
4:20 Meta is not a Python thing, it's a Django thing. but Django is a Python thing, right?
والله يا اب صلعه قعد تجيني في جررح عديييل
Please solve this question
Write a function to find if a given inputted word can be made from the string.
Example1: If a string “cat” is entered in the input string 1 then the alphabets in the master string
allocate ‘c’,’a’,’t’ as already in use. So, the next input string entered will be matched with the
remaining characters in the master string.
Example2: If the second string entered as ‘egg’ then the required character ‘e’,’g’,’g’ checked from
the balance master string. If it's found in the master string, then ‘Yes’ else ‘No’
Setup Django form with following fields.
Master String, String 1, String 2, String 3, String 4
Sample Input
Master String: aabcglactdde
String 1: cat
String 2: egg
String 3: bat
String 4: ball
Sample Output
Cat: Yes
Egg: No
Bat: No
Ball: No
Note: ‘bat’ is marked as ‘no’, because in the given master string(aabcglactdde) only one ‘t’ is
given and it's already used for ‘cat’.
lol no one is going to do your homework for you
@@Codemycom it's not home work . I did partially completed. But I am confused .
If we directly go to the url: /add_venue?submitted=True
It takes us to the page saying you submitted successfully, how to restrict this page only when we submit and will not show if we go directly to the url??
I had to refactor my view to look like the code below. Otherwise I kept getting the error: cannot access local variable 'form' where it is not associated with a value
refactored:
def add_venue(request):
submitted = request.GET.get('submitted', False)
if request.method == 'POST':
form = VenueForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/add_venue?submitted=True')
else:
submitted = True
else:
form = VenueForm()
context = {'form': form, 'submitted': submitted}
return render(request, 'addiction_events/add_venue.html', context)
Sir, i am getting this error "GET /add-venue?submitted=True HTTP/1.1" 404 2634
'/add_venue?submitted=True ... I don't get this and it gives me this error - The view events.views.add_venue didn't return an HttpResponse object. It returned None instead. Please help me out!
check your code vs the video, you just did something different.
Thank you!!, this video was very helpful.
Glad you liked it!