Django forms facilitate user input handling the same way that HTML forms do but in Django’s case, the view
gets a request, performs actions required such as reading data from the models, then it generates and returns an HTML page or refreshes the current page if a path isn’t specified. Once this is all done the server processes the data that the user input and redisplays the page if there are any errors.
In steps this would go:
Display the default form for the user.
Receive data from a submit request and bind it to the form
Clean and validate the data
If data invalid, re-display form with error messages
If data is valid, perform required
actions
Once complete, redirect user to specified page.
Some of the key components for a Django form are:
forms.py
file inside of the application directory
Form
class, when imported from django library
from django import forms
class SampleForm(forms.Form):
pass
forms
library
class SampleForm(forms.Form):
email = forms.EmailField()
References
Django Tutorial Part 9: Working with forms