From what I have seen, many people struggle to understand how forms work and how they are used.
*Here is a quick primer for you:*
**Forms are python classes** which you can assign **specific fields** to, similar to the model fields syntax. Every form field has a **widget** associated with it. This widget is used to describe, which **HTML tag** this particular field should turn into, when the form is shown on the client side.
Forms can be used to **generate HTML code** on the client side when we print them out on our template. Another common use case is **validating the data** that the user tries to post to our backend, because we can never trust user input.
You divide forms into two types:
\- **unbound** forms: don't have any data associated with them
\- **bound** forms: have data "bound" to them.
Another class is called the **ModelForm**. Think of them as an abstraction that is meant to make working with forms that are **related to certain models** easier. Instead of getting the data out of them manually and using ModelName.objects.create\(...\).save\(\) to save them to the database, we can simply call **form.save**\(\) and it's done for us!
If you want to dig a bit deeper into this and see the concepts in action, I published a video about django forms for beginners which you can find here:
[https://www.youtube.com/watch?v=3XOS\_UpJirU](https://www.youtube.com/watch?v=3XOS_UpJirU)
I hope it helps!
Great video!
I was looking for such a video a few weeks ago. Good to see this!
I wanted to ask you, how to create forms with pop-up UI?
I am working on a project, where on a page there are many categories, and each category can have multiple items.
With end of each catagory, there is a button to add a new item for that particular category!
You click that button, a pop up drops in with a form to enter new items field.
How can we make this happen?