Django Forms Tutorial For Beginners - Get Started Fast! (2018)

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024
  • 7 Tips For Getting Better At Django:
    mailchi.mp/dea...
    In this django forms tutorial for beginners, you will learn how to perform common tasks with django forms.
    Django forms can be used for a variety of things, such as generating the HTML form markup or validating a form.
    A django form is just a class that contains fields that specify a widget, which is used for telling python which HTML tag you want to generate for this particular field.
    By the end of this video, you will have a good overview of how to use django crispy forms to make working with forms easier, how to use ModelForms and we'll also cover an interesting field called the MultiValueField and use it to create our own field.
    Bootstrap CDN (scroll down to BootstrapCDN and get the single line snippet under CSS only):
    getbootstrap.com/
    If you enjoyed this video, make sure to subscribe and share it with anyone you think could enjoy it as well.
    I hope to see you inside of the next episode,
    Cheers.

Комментарии • 174

  • @MarkGla55
    @MarkGla55 2 года назад +2

    Thank you. I have looked at many videos about working with Django. Yours is practical and to the point. Easy to understand and follow along.

  • @theodorehowell8869
    @theodorehowell8869 5 лет назад +55

    I trust you because I can hear your keyboard ;)

  • @logancarey337
    @logancarey337 4 года назад +4

    Thank you for having a good mic!!! So hard to find some tutorials that you can hear!

  • @adhysh
    @adhysh 3 года назад +4

    Thank you ! clear, concise and quite comprehensive on using crispy forms

  • @oyatilloismoilov5540
    @oyatilloismoilov5540 2 года назад +1

    Thank you bro I took amazing informations about django forms from your this amazing tutorial

  • @neelisivasai9023
    @neelisivasai9023 4 года назад +1

    Thank you so much sir....🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

  • @caleb9195
    @caleb9195 4 года назад +1

    Thanks man

  • @berkalkan3382
    @berkalkan3382 3 года назад +1

    This is still helpful for a newbie like me. Thanks a lot my guy.

  • @thalindabandara1552
    @thalindabandara1552 5 лет назад +2

    Thank you very much for your tutorial! just spend 2 hours correcting one mistake and only you showed me that

  • @martincronje5242
    @martincronje5242 Год назад +1

    Thanks for the video, would it be possible to show how you can apply bootstrap to the modelform class?

  • @vrfEducation
    @vrfEducation Год назад +1

    useful and concise.

  • @iancarr3923
    @iancarr3923 5 лет назад +3

    Another very useful video. Best example of crispy forms that I have seen. Many thanks.

  • @anindyachatterjee4765
    @anindyachatterjee4765 4 года назад +1

    thanks for this wonderful video

  • @ultimatetradingsecret
    @ultimatetradingsecret 3 года назад +1

    Really Liked it

  • @yumeileventhal3069
    @yumeileventhal3069 3 года назад +1

    Awesome tutorial!!! Thank you very much!

  • @kiranraj-dw5gq
    @kiranraj-dw5gq 4 года назад +1

    Awesome.Thanks

  • @anaynasingh9507
    @anaynasingh9507 2 года назад +1

    Thanks a lot!

  • @troyforrester1991
    @troyforrester1991 4 года назад +1

    Bro you are a life saver

  • @epic9675
    @epic9675 3 года назад +1

    thank you very much

  • @sarathchandran2815
    @sarathchandran2815 4 года назад +1

    Man you are awesome 😘😘. You deserve more views 👍

  • @OthmanAlikhan
    @OthmanAlikhan 2 года назад +1

    Thanks for the video =)

  • @KevinTempelx
    @KevinTempelx 4 года назад +1

    Thank you

  • @jamesmckinnon4141
    @jamesmckinnon4141 4 года назад +2

    When I set up the RegexValidator for entering only letters in the name field the message that say "enter a valid first name" shows up when there is only numbers in the field but when there is a combination of letters, such as "james1" , the message doesn't appear and the name is submitted. Is there a way to not allow any numbers at all?

  • @gauravpoudel7288
    @gauravpoudel7288 5 лет назад +2

    wow. thank u so much. exactly what i was looking for

  • @davudhaci5379
    @davudhaci5379 4 года назад +1

    Thank you man its very helpful!

  • @JJnnaatt
    @JJnnaatt 4 года назад +1

    Very useful, especially the multivaluefield part!

  • @flaman75
    @flaman75 6 лет назад +6

    O melhor do youtube, claro como a água.

  • @angladephil
    @angladephil 3 года назад +3

    Hi, thanks for the tuto.
    Compared to HML+JS, this seems overcomplicated and I can't see any advantage to code with Python.

    • @jasiahmarvin23
      @jasiahmarvin23 3 года назад

      You prolly dont give a shit but does anybody know a way to log back into an instagram account..?
      I was stupid lost the login password. I love any tips you can give me

  • @omparikh4426
    @omparikh4426 4 года назад +1

    why you changed from action=post to method-post in forms.html?

  • @msalih
    @msalih 2 года назад +1

    you know this job

  • @serhii.chumachenko
    @serhii.chumachenko 6 лет назад +6

    Thanks!

  • @arielol89
    @arielol89 4 года назад +1

    Great video.
    I really likes how explain it!
    Thanks!

  • @Raphael-bq1fc
    @Raphael-bq1fc 2 года назад

    what's the use of super_init_ in NameWidget and the decompress function again?

  • @praneethkondra1882
    @praneethkondra1882 Год назад

    Hi there is an issue at the end of the video, I'm not able to switch to snippet page it says an error VariableDoesNotExist at /snippet
    Failed lookup for key [helper] in

  • @Thesrik23
    @Thesrik23 6 лет назад +3

    Thank you, Gabriel.
    Love you Man

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +1

      Always happy to help Srikant! Thanks for watching.

    • @Thesrik23
      @Thesrik23 6 лет назад +1

      The Dumbfounds
      What will be the next video about??

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +1

      Srikant It will be either about REST APIs or how to extend the user model ;)

    • @Thesrik23
      @Thesrik23 6 лет назад +1

      Hey Garbriel, what if my page contains two or more forms! How do I let the view know that I'm submitting data from a particular form?

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +1

      Hey Srikant, there are a couple of approaches. You can use different actions on the forms and handle them in different views. Another approach would be to assign names to the input buttons to determine which one was clicked. You can find more info on that approach here: stackoverflow.com/questions/866272/how-can-i-build-multiple-submit-buttons-django-form

  • @niranjantamhane3602
    @niranjantamhane3602 4 года назад +1

    I downloaded video powered it with external amplifier app still can't hear you properly and my headphone is broken

  • @yt-1161
    @yt-1161 2 года назад

    how can I add some space between name fields in the widget ? In my form the fields are flush

  • @jatinaggarwal2372
    @jatinaggarwal2372 6 лет назад +1

    Great job ..

  • @SamChaneyProductions
    @SamChaneyProductions 4 года назад +3

    Thanks so much for this video but could you do a video that covers using a GET request instead of POST using Django forms? All of the examples I can find online including this one only cover POST.

    • @johng5261
      @johng5261 2 года назад

      why did you want a GET?

  • @flavius2884
    @flavius2884 3 года назад

    At 7:34 it shows me TypeError at /
    context must be a dict rather than set.
    What did I done wrong? And I am sure I wrote the same code in the video.

  • @bedux2009
    @bedux2009 5 лет назад +1

    That's wonderful explanation. I am subscribing to it. Do you have any video to write and read from CSV files using Python in Django ? I use Sublime as Editor in Windows 10.

  • @ayamada2905
    @ayamada2905 5 лет назад +1

    that's super interesting video. thank you.

  • @ivospironello6451
    @ivospironello6451 Год назад

    Why did you create 2 classes in forms.py with separated information? I want to have everything in one class

  • @anuoluwapowahab729
    @anuoluwapowahab729 5 лет назад +2

    Hello, nice tutorial but I got this error Failed lookup for key [helper] in

    • @soumi7356
      @soumi7356 4 года назад

      same problem. Have you solved it?

    • @anuoluwapowahab729
      @anuoluwapowahab729 4 года назад

      @@soumi7356 No, I have not

    • @SaeedAhmed-zo3om
      @SaeedAhmed-zo3om 3 года назад

      Sorry, I'm a little late but hope other people will be helped.
      You havent changed the SnippetForm class in forms.py to get the bootstrap you'll need to do that in order to get that to work, Just look at the urls.py and you'll understand that the ModelForm and the other Form are in different locations

  • @kudakwashedzorani7576
    @kudakwashedzorani7576 3 года назад

    Please help, how do I save the form created at the end of the video?

  • @vitisuporte6996
    @vitisuporte6996 5 лет назад +1

    Thanks......!!!!!

  • @Firstusee256
    @Firstusee256 6 лет назад +1

    Awesome..

  • @EddyCaffrey
    @EddyCaffrey 6 лет назад +1

    I really liked. thank you bro

  • @kaustavsengupta8757
    @kaustavsengupta8757 6 лет назад +1

    Great video. But can you also try to explain the django models CRUD? Might be helpful

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +2

      Thanks! Do you mean what CRUD is in general and how to apply it do Django?

    • @kaustavsengupta8757
      @kaustavsengupta8757 6 лет назад +1

      @@thedumbfounds767 Applying in django and a brief introduction about what CRUD is might be helpful too

  • @kudakwashedzorani7576
    @kudakwashedzorani7576 3 года назад

    I am getting an error 19:10 minutes, it is saying
    Failed lookup for key [helper] in
    During handling of the above exception ("Key 'helper' not found in 'SnippetForm'. Choices are: body, name."), another exception occurred:
    It only works after removing form.helper in your line 12, what should I do please help?

  • @JOHNBOSCOADAM
    @JOHNBOSCOADAM 5 лет назад +2

    Thank you for sharing, Am sure you will not disappoint me when am press the subscribe button, hahahaha ):

  • @shirinebadi4104
    @shirinebadi4104 3 года назад

    Hello. When I import forms in view I get circullar import error. how can i fix it?

  • @jiwan88
    @jiwan88 4 года назад

    What are the 7 tips for getting better at django mentioned on description, the links didn't opened ?

  • @veliea5160
    @veliea5160 5 лет назад +2

    Snippet form is not saving. Everything worked fine so far? Can anyone help pls

    • @ferror18
      @ferror18 5 лет назад

      mine neither, csrf token failing even though i have in the template and syntax is correct

    • @ferror18
      @ferror18 5 лет назад

      just is i typed my previous comment figured out the in my anchor tag i had placed the enctype attribute to text plain, i did that following a previous tutorial i removed that and it started working.

  • @williamkidwell1504
    @williamkidwell1504 6 лет назад +2

    Hey Gabriel - Great tutorial! I haven't checked your GitHub page, but is the code for this available?

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +2

      Hi William. Yes, here is the link to the repo: github.com/Rechunk/django-forms-tutorial

  • @benjohnk622
    @benjohnk622 3 года назад

    Hey, could you please give me the link to your oop concepts which u tells in this video?

  • @enian82
    @enian82 6 лет назад

    What if you want a form where the user enters couple of values you have to multiple with a standard value from the table and display it in the same form.
    example:
    The user has two inputs
    1. Pick a category A,B,C
    2.Enter a number.
    In the back end the database has these values
    A=2
    B=4
    C=6
    Our goal is to print what is received in 1 and multiple by 2 and display it in a separate line
    ------------------------------------------------------------
    Example 1
    1. User enters A
    2. User enters 10
    the output should be 20
    Can this be done using Django?
    Thank you

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад

      Krish Kk Sure! Just create a normal form. One input is a choicefield. You can specify the choices as tuples with A and 2, B and 4, and C and 6. The second input would be an IntegerField (in the case that you only want to be able to multiply by who numbers). Then, just process the form, get the two values out of it, multiply and you‘re done :) Was that understandable?

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад

      Oh, and as far as the displaying goes: either do it via AJAX if you want it without reloading the page, or just pass it in your context when rendering the template.

  • @AlThePal78
    @AlThePal78 3 года назад

    after I made my superuser what admin route are you talking about?

  • @Firstusee256
    @Firstusee256 6 лет назад +2

    Please upload videos on slug field and signals

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад

      I do plan a video on identifiers (slug, uuid). Don't know about signals, yet.

    • @akashkandpal1832
      @akashkandpal1832 5 лет назад

      @@thedumbfounds767 please sir make more videos. I have been waiting for 2 weeks now.

  • @Tahreek_Films
    @Tahreek_Films 6 лет назад +1

    Thanks :)

  • @lehoanglong9794
    @lehoanglong9794 4 года назад

    That's really great, but when I do with crispy it has "*" in label. Example "Email *", how can I hidden it.

  • @NETFQ
    @NETFQ 6 лет назад +1

    What if you wanted to use a bootstrap options form ... how can you postback the elected options and have Django pick it up using requests.POST ? ... I want to be able to do this without using modals.

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +1

      NETFQ - Gameplay then don't subclass from ModelForm, only from Form. Does this help? docs.djangoproject.com/en/2.0/ref/forms/widgets/#setting-arguments-for-widgets

    • @NETFQ
      @NETFQ 6 лет назад

      thanks .. still not sure how you do it though.. I want to use this: getbootstrap.com/docs/4.0/components/list-group/ ... the 'list' to sent to the template and auto generated via a {% for x in y %} loop ... javascript lets you then select multiple items from the list ... just need to know how to get the selected (active) items from the list back to the view?

    • @NETFQ
      @NETFQ 6 лет назад

      basically the multiselect list is dynamic, variable number of items which users can select.

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +1

      Take a look at the second answer of this: stackoverflow.com/questions/15393134/django-how-can-i-create-a-multiple-select-form. Instead of rendering the form with crispy forms, you can also just type out the html manually. Just make sure to assign a name to your inputs. If that doesn't solve your problem, I'll try to resemble it tomorrow and send it your way.

    • @NETFQ
      @NETFQ 6 лет назад

      ok last question I promise :)
      How can I populate OPTIONS var with the list of items? How can I pass this list to the form class?

  • @shylasree5861
    @shylasree5861 4 года назад

    On which platform r u executing the commands

  • @RoyalG254
    @RoyalG254 4 года назад +1

    you are wonderful dude thanks soo much...

  • @rehankhaled4886
    @rehankhaled4886 5 лет назад

    The Dumbfounds I am getting error in the snippet form in views.py.The following error is The view myapp.views.snippet_detail didn't return an HttpResponse object. It returned None instead.
    Please help!

  • @shylasree5861
    @shylasree5861 4 года назад

    On platform r u executing the commands

  • @picsjpg1285
    @picsjpg1285 4 года назад

    Which server u use I didn't understand

  • @BrendanMetcalfe
    @BrendanMetcalfe 4 года назад +2

    This is the only tutorial I've seen where they use the FormHelper haha

  • @shahidullahmiazi
    @shahidullahmiazi 6 лет назад

    Awesome! Please, putting action page later.

  • @vikashkumardas3741
    @vikashkumardas3741 5 лет назад +1

    cool

  • @mehdimortaz351
    @mehdimortaz351 5 лет назад +1

    thanks

  • @ShemTelemaque
    @ShemTelemaque 5 лет назад

    Also a discord channel might be nice to create and grow this community.

  • @kenjohnsiosan9707
    @kenjohnsiosan9707 6 лет назад

    Hi sir, Is this some kind of alternative way of creating forms? can i still create the form in html and use it in my template and expects the same result ? Thanks

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +2

      Sure, the end result always has to be form HTML the user can use. You can skip the crispy forms part if you want and write raw HTML and CSS. I'll soon have a video up on customizing forms! :)

    • @kenjohnsiosan9707
      @kenjohnsiosan9707 6 лет назад

      @@thedumbfounds767 thanks... looking forward on that 😃. im learning a lot from your videos.

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +1

      @@kenjohnsiosan9707 that's great to hear!

  • @carloscastanyo
    @carloscastanyo 5 лет назад

    Can I use crispy forms with ModelForm? Because I tried as you in the video and there are problems.

  • @vedxgaming8216
    @vedxgaming8216 6 лет назад

    Hey Gabriel,
    On my end it's not showing name and email when we use print...

  • @muhammadilyas2179
    @muhammadilyas2179 4 года назад

    how to design it

  • @Student-kf7qw
    @Student-kf7qw 3 года назад

    Its almost impossible to listen your voice. Check your audio recording device.

  • @rajnisaini7733
    @rajnisaini7733 5 лет назад

    raise TypeError('HTTP status code must be an integer.')
    TypeError: HTTP status code must be an integer. i am facing issue in this line return HttpResponse(request,'form.html',{'form':form}) ..Hw i can reslove this

    • @thedumbfounds767
      @thedumbfounds767  5 лет назад

      Coming a bit late, but I think you meant to use the render() shortcut instead of returning the HtthResponse right away (the render function will do that for you).

  • @obiwankenobi9987
    @obiwankenobi9987 6 лет назад

    Hi bro. Please record video ajax form and vuejs +django. Sorry my English

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад

      Hi Ivan, I don't think VueJS will come anytime soon. Thanks for the recommendation!

  • @nzs1
    @nzs1 4 года назад

    Specify the snippet as "snippet one" and the body as, I don't know, "nnsjsjsn" 😂😂😂

  • @akashkandpal1832
    @akashkandpal1832 5 лет назад

    you said that you will provide a link to the python tuts in the video , where is that link ?

    • @thedumbfounds767
      @thedumbfounds767  5 лет назад

      Which python tuts? Can you point me to where I said that in the video?

    • @akashkandpal1832
      @akashkandpal1832 5 лет назад

      @@thedumbfounds767 Sorry, I guess you said to watch other videos for Django.

    • @mtaylor2938
      @mtaylor2938 5 лет назад

      ​@@thedumbfounds767 You mention putting a link to your Python Class tutorial. You say at this @16:50. By the way, I found this tutorial very interesting.

  • @ibtihelhacheni8365
    @ibtihelhacheni8365 5 лет назад

    how to represent a duration field ?

  • @dinonppa1
    @dinonppa1 6 лет назад

    When saving. How do you save a choicefield?? I can not seem to get the choicefield to save to the database..
    Can you please help?

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад

      Could you post your code on bpaste.net or somewhere else?

    • @dinonppa1
      @dinonppa1 6 лет назад

      The Dumbfounds I will post it tomorrow night. Thank you! I can save everything else to the database except for that choicefield, i just don’t know how to add it to the models.py, I believe that’s the issue

    • @dinonppa1
      @dinonppa1 6 лет назад

      github.com/dinonappa1/CIProject
      Here is the code

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад +1

      A choicefield has the user select a value which you want to store on database (I guess). So, you don't have to create a choicefield on the model, just use charfield and set choices=... (whatever choices you have). Take a look at this stackoverflow answer for more information: stackoverflow.com/questions/8077840/choicefield-in-django-model. Does that solve your problem? Btw: seems like you're building a cool project!

    • @dinonppa1
      @dinonppa1 6 лет назад

      Awesome! That did the trick! Thank you!
      And thank you! The project is pretty neat! Taking a lot of work. Learning a lot by watching your videos. Keep them coming!

  • @sabmost
    @sabmost 2 года назад

    Pls where is the source

  • @jacktimber5969
    @jacktimber5969 4 года назад

    10:14 what is form = ContactForm(request.POST)

    • @sahilasopa3905
      @sahilasopa3905 4 года назад

      When called it will post the data

    • @chawza8402
      @chawza8402 4 года назад +1

      request.POST will return information body of HTTPresponse. in this case, name and email. and then we use the value to make an object from the ContactForm that he previously created. this way, he didn't need to do manually like "form = ContactForm(name=request.POST["name"], email=request.POST["email"]".
      or I could say creating the form right from the request parameter.

  • @harshabindas5996
    @harshabindas5996 6 лет назад

    Hey people I need ur help... How to send an email using python 3 in Django? Please help me out!

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад

      Hey Harsha, take a look at this: docs.djangoproject.com/en/2.1/topics/email/

  • @hemanth6951
    @hemanth6951 5 лет назад

    Very complicated in this modern world

  • @SJ-go2wf
    @SJ-go2wf 4 года назад

    Do u have code in github?

  • @ShemTelemaque
    @ShemTelemaque 5 лет назад +1

    Hello I have followed successfully to time code 20:49 but I have run into a error which after a researching am not sure what I am missing
    Error code: "Failed lookup for key [helper] in "
    code so far github.com/drmaq/form-project.git
    github.com/drmaq/form-project.git

  • @govindaramana.n.586
    @govindaramana.n.586 4 года назад +1

    dasi onnume puriyala da

  • @tarunchaudhary3958
    @tarunchaudhary3958 4 года назад +3

    More explanation is required.. else video is good..

  • @briani466
    @briani466 4 года назад

    source code?

  • @runthomas
    @runthomas 6 лет назад

    I HATE even the mention of the word 'context data' i dont know why you need it ..what it means ...when to do it ..its just so impossible to grasp

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад

      Context data is just the data you pass to the template used for rendering it. It is just a dictionary with key-value pairs.

    • @runthomas
      @runthomas 6 лет назад

      thank you , that would make sense.

    • @thedumbfounds767
      @thedumbfounds767  6 лет назад

      just play around with it and you'll see how it works :)

  • @footballfan7796
    @footballfan7796 5 лет назад +1

    need your email

  • @tubehelpr
    @tubehelpr 5 лет назад

    super hot fire

  • @ChengPhansivang
    @ChengPhansivang 2 года назад

    This tutorial is literally not for beginners it's fast then my wifi

  • @govindaramana.n.586
    @govindaramana.n.586 4 года назад

    fuckign

  • @andrewmartinez8340
    @andrewmartinez8340 3 года назад

    jeez, your better off learning basic javascript

  • @lordkrishna7480
    @lordkrishna7480 Год назад

    VariableDoesNotExist at /snippet/
    Failed lookup for key [helper] in
    getting like this,,,please help me

  • @sahilarora4602
    @sahilarora4602 5 лет назад +1

    Thank you