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

ความคิดเห็น • 132

  • @Codemycom
    @Codemycom  3 ปีที่แล้ว +4

    ▶️ 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

  • @mosesejele5089
    @mosesejele5089 2 ปีที่แล้ว +11

    @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.

  • @MrHossain2357
    @MrHossain2357 8 หลายเดือนก่อน +1

    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.

    • @Codemycom
      @Codemycom  8 หลายเดือนก่อน +1

      Glad you enjoyed it!

  • @codewithmorris6492
    @codewithmorris6492 2 ปีที่แล้ว

    after stucking for so long, and then watched your video, I have finally get the solution. TQVM. Subscribed

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      Glad I could help

  • @sambhusdharan7532
    @sambhusdharan7532 ปีที่แล้ว +3

    All your classes are at next level.. hats off.. love from india

  • @CryptotechCh-tw5ib
    @CryptotechCh-tw5ib ปีที่แล้ว

    Your video helped me a lot to understand forms in the minimum time! Thank you so much for the great job

    • @Codemycom
      @Codemycom  ปีที่แล้ว

      Happy to help!

  • @aniket.r.thakur
    @aniket.r.thakur ปีที่แล้ว +2

    1000th Like is Mine !!!!

  • @bhs_codz2534
    @bhs_codz2534 2 ปีที่แล้ว +2

    You are one of the best teacher in the world love from india

  • @joshuabarawa9232
    @joshuabarawa9232 2 ปีที่แล้ว

    Thnaks man...You always have what i need

  • @behroozfalsafi7951
    @behroozfalsafi7951 2 ปีที่แล้ว

    Thank you for the video. It was very helpful.

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      Very welcome!

  • @Good-and-Geeky
    @Good-and-Geeky 10 หลายเดือนก่อน

    Tried FastAPI, Flask and now Django.... Loving Django. It makes so much sense. Good tutorial. Thanks

    • @Codemycom
      @Codemycom  10 หลายเดือนก่อน

      Glad you like em!

  • @agustin-xc8rg
    @agustin-xc8rg 2 ปีที่แล้ว

    Thank you!!, this video was very helpful.

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      Glad you liked it!

  • @saminrahman5165
    @saminrahman5165 ปีที่แล้ว +2

    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

    • @Codemycom
      @Codemycom  ปีที่แล้ว

      Glad you're enjoying it!

  • @Jonny-gi4iz
    @Jonny-gi4iz ปีที่แล้ว

    Thanks for the video, it was very helpful in learning django!

    • @Codemycom
      @Codemycom  ปีที่แล้ว

      Happy to hear it!

  • @mxmx8808
    @mxmx8808 2 ปีที่แล้ว +1

    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 :)

  • @israahussein7582
    @israahussein7582 2 ปีที่แล้ว

    great explanation !

  • @hayet3198
    @hayet3198 ปีที่แล้ว

    Thank you very much, Heisenberg

  • @raminfarzi4229
    @raminfarzi4229 9 หลายเดือนก่อน

    sooooo good video very useful thanks

    • @Codemycom
      @Codemycom  9 หลายเดือนก่อน

      Welcome!

  • @varanushimu6015
    @varanushimu6015 3 ปีที่แล้ว

    Hey this project is amazing. Plz finish this peoject ASAP....i cant wait!

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว +1

      Thanks! New video every Wednesday

  • @cadenwiles4981
    @cadenwiles4981 ปีที่แล้ว

    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

  • @Kingofnekos_osu
    @Kingofnekos_osu ปีที่แล้ว +1

    hello, when i submit the form i get submitted = True but it wont return your venue addded succesfully why

  • @naedeezy8967
    @naedeezy8967 2 ปีที่แล้ว

    I love you man!

  • @user-fn3ro5rm1d
    @user-fn3ro5rm1d ปีที่แล้ว +1

    thank you

  • @silvermind4222
    @silvermind4222 ปีที่แล้ว

    How can I use textarea to take input for one of the table in django

  • @panfi1408
    @panfi1408 2 ปีที่แล้ว

    How could I print out what Venue was created in the /add_venue?submitted=True?

  • @rafaeljesus9187
    @rafaeljesus9187 5 หลายเดือนก่อน

    How do you do to have a label for the primary key of the class?

  • @yunikashrestha5345
    @yunikashrestha5345 ปีที่แล้ว

    I'd like to add an author for the form, where the author being the logged in user themselves. How do I do It?

  • @alemagnific69
    @alemagnific69 2 หลายเดือนก่อน

    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.

    • @Codemycom
      @Codemycom  2 หลายเดือนก่อน

      your questions are all answered in the videos

  • @sartajjamalchowdhury5281
    @sartajjamalchowdhury5281 3 ปีที่แล้ว

    Thanks !!!!!

  • @lorimedicenter4439
    @lorimedicenter4439 ปีที่แล้ว

    thank you very much .you help us to create our project.... !!! could you make video about ecommerce

    • @Codemycom
      @Codemycom  ปีที่แล้ว +1

      Happy to hear it!

  • @eduardjogi
    @eduardjogi 3 ปีที่แล้ว +2

    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!!

    • @eduardjogi
      @eduardjogi 3 ปีที่แล้ว +1

      ALready got it :)..... Missed a line :(

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว +1

      @@eduardjogi Yeah was gonna suggest putting is aside for a few hours and checking it again with fresh eyes

    • @flavius2884
      @flavius2884 3 ปีที่แล้ว

      @@eduardjogi I got the same problem. What line?

    • @eduardjogi
      @eduardjogi 3 ปีที่แล้ว +1

      @@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 :)

  • @dmitry8732
    @dmitry8732 ปีที่แล้ว

    what if i use namespace:name, how can i add "?submitted=True" ?
    i have error "Path not found"

  • @MrBrightsideTK
    @MrBrightsideTK 3 ปีที่แล้ว

    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.

    • @BonesD23
      @BonesD23 2 ปีที่แล้ว

      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.

  • @henrykonandore4860
    @henrykonandore4860 3 ปีที่แล้ว

    thank sir

  • @seeemawn
    @seeemawn 2 ปีที่แล้ว

    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 :)

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      Yes, it's necessary

  • @aribalmarceljames9908
    @aribalmarceljames9908 2 ปีที่แล้ว

    can you help me why in my forms.py the bootstrap wont activate

  • @piotrrybka318
    @piotrrybka318 10 หลายเดือนก่อน

    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.

    • @Codemycom
      @Codemycom  10 หลายเดือนก่อน

      Django auto increments id columns automatically.

  • @sravanigundepalli3513
    @sravanigundepalli3513 ปีที่แล้ว

    how to add 2+venues or events at once in form of table

  • @jimmybatista6488
    @jimmybatista6488 2 ปีที่แล้ว +1

    when adding venue i do not get the page added sucessfully redirect but it does add it to the database

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      what did you do differently from the video?

    • @Kennerdoll
      @Kennerdoll ปีที่แล้ว

      @@Codemycom same here so right now I'm still checking but I can see it in the web browser '/add_venue?submitted = True'

  • @HuyNguyen-xp4ro
    @HuyNguyen-xp4ro 3 ปีที่แล้ว

    Thanks for best video. Can you tutorial style label djangoform ? Thank you !!!

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      Yeah, I have videos on that

    • @HuyNguyen-xp4ro
      @HuyNguyen-xp4ro 3 ปีที่แล้ว

      @@Codemycom ya, I think we need to do this without bootstrap, I want to learn basically ! Thank you :D

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      @@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

  • @ruffyistderhammer5860
    @ruffyistderhammer5860 ปีที่แล้ว

    at 18:39 how can line 20 ever be accessed?

  • @mdgolamrabbani507
    @mdgolamrabbani507 3 หลายเดือนก่อน

    i want to show how html redirecting part is working? Whict is the other vedio that you have shown this

    • @Codemycom
      @Codemycom  3 หลายเดือนก่อน

      Sorry, don't know what you mean.

  • @balwinderrani809
    @balwinderrani809 3 ปีที่แล้ว +1

    Hello first comment

  • @mohanasubbu5861
    @mohanasubbu5861 2 ปีที่แล้ว

    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...

    • @mohanasubbu5861
      @mohanasubbu5861 2 ปีที่แล้ว

      please reply me... i am stuck in this problem

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      what did you do differently from the video?

  • @jithingeorge1946
    @jithingeorge1946 4 หลายเดือนก่อน

    class Meta allows you to edit the metadata......cheers!

    • @Codemycom
      @Codemycom  4 หลายเดือนก่อน

      lol yeah

  • @vikasmaur7947
    @vikasmaur7947 3 ปีที่แล้ว

    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?

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      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?

    • @vikasmaur7947
      @vikasmaur7947 3 ปีที่แล้ว

      @@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

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      @@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.

    • @vikasmaur7947
      @vikasmaur7947 3 ปีที่แล้ว

      @@Codemycom okay i'll try doing that
      Thanks

    • @vikasmaur7947
      @vikasmaur7947 3 ปีที่แล้ว

      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.

  • @bede_hampo
    @bede_hampo 2 ปีที่แล้ว

    Good day sir, please what's the best way to store phone number in Django models ?

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      Probably just as characters

  • @jeremyeddlemon
    @jeremyeddlemon 3 หลายเดือนก่อน +1

    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?

    • @Codemycom
      @Codemycom  3 หลายเดือนก่อน +1

      Of course it works with Django 5

    • @jeremyeddlemon
      @jeremyeddlemon 3 หลายเดือนก่อน

      @@Codemycom Yes, sir. I will keep digging. You have great a channel, btw.

  • @syedkhizar8624
    @syedkhizar8624 2 ปีที่แล้ว

    didn't return an HttpResponse object.

  • @bahdev1324
    @bahdev1324 3 ปีที่แล้ว

    Is this going to be part of ur Codemy courses?

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว +1

      No, this is just on youtube

    • @bahdev1324
      @bahdev1324 3 ปีที่แล้ว +1

      @@Codemycom
      OK
      I bought ur courses last month
      Just want to know if some videos here are included there...

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว +1

      @@bahdev1324 Generally speaking, the paid courses are not free on TH-cam...that's why they're paid.

    • @bahdev1324
      @bahdev1324 3 ปีที่แล้ว

      @@Codemycom
      Okay sir thank you...

  • @mynameisgod1135
    @mynameisgod1135 3 ปีที่แล้ว

    Please include hashing in this video series

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      Not really likely, but you never know.

  • @assaulttork6384
    @assaulttork6384 2 ปีที่แล้ว

    How do you prevent user from going back to same form by pressing back button?

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว +1

      The browser handles that

  • @aguspe532
    @aguspe532 3 ปีที่แล้ว

    Hi! Do you have the code in Github?

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว

      github.com/flatplanet/djangoblog

  • @bidhyapokhrel1006
    @bidhyapokhrel1006 3 ปีที่แล้ว

    hello plz make a video for login and registration by using forms.py files

    • @Codemycom
      @Codemycom  3 ปีที่แล้ว +1

      Yeah will probably get to that

  • @gouthamgoutham7640
    @gouthamgoutham7640 3 ปีที่แล้ว

    Sir pls do followers and following system

  • @learnwithnawf246
    @learnwithnawf246 3 ปีที่แล้ว

    The output looks different for me but I wrote the same code is there any reason

  • @christymarychacko4323
    @christymarychacko4323 4 หลายเดือนก่อน

    sir I can't display the message. Could you help me?

    • @Codemycom
      @Codemycom  4 หลายเดือนก่อน

      Just rewatch the video and discover what you did differently from the videos. I show you everything you need.

    • @christymarychacko4323
      @christymarychacko4323 4 หลายเดือนก่อน

      @@Codemycom 😀Thank you sir

  • @hackerdaddy2828
    @hackerdaddy2828 3 ปีที่แล้ว

    hello third comment

  • @TheDarienspider
    @TheDarienspider 2 หลายเดือนก่อน

    I wish he would increase the screensize so we can see all of the code and not just roughly 50char length

    • @Codemycom
      @Codemycom  2 หลายเดือนก่อน

      code is in the pinned comment champ

  • @1412-kaito
    @1412-kaito ปีที่แล้ว

    4:20 Meta is not a Python thing, it's a Django thing. but Django is a Python thing, right?

  • @mohamedmamoun1870
    @mohamedmamoun1870 3 ปีที่แล้ว

    والله يا اب صلعه قعد تجيني في جررح عديييل

  • @chanchalkrishna3336
    @chanchalkrishna3336 ปีที่แล้ว

    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’.

    • @Codemycom
      @Codemycom  ปีที่แล้ว

      lol no one is going to do your homework for you

    • @chanchalkrishna3336
      @chanchalkrishna3336 ปีที่แล้ว

      @@Codemycom it's not home work . I did partially completed. But I am confused .

  • @k.t.5184
    @k.t.5184 ปีที่แล้ว

    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??

  • @kittyrah2800
    @kittyrah2800 8 หลายเดือนก่อน

    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)

  • @eleksonkurbah4013
    @eleksonkurbah4013 2 ปีที่แล้ว

    Sir, i am getting this error "GET /add-venue?submitted=True HTTP/1.1" 404 2634

  • @muskankaushik3834
    @muskankaushik3834 ปีที่แล้ว

    '/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!

    • @Codemycom
      @Codemycom  ปีที่แล้ว

      check your code vs the video, you just did something different.

  • @ngamenifranck1875
    @ngamenifranck1875 2 ปีที่แล้ว

    Thank you!!, this video was very helpful.

    • @Codemycom
      @Codemycom  2 ปีที่แล้ว

      Glad you liked it!