Almost every real application has to accept input from users: sign-up pages, contact forms, search boxes, and content editors. Handling that input safely is harder than it looks, because you have to render fields, read the submitted data, check that it is valid, and show helpful errors. Django's forms framework does this work for you.
In this module you will learn how to define a form with the
Form class, how to build one directly from a model with
ModelForm, and how to render it in a template and process it in a
view on POST. You will then learn how validation
works: built-in field checks, custom validators, and clean() methods
for rules that involve more than one field, along with how to display error
messages.
Watch the lessons in order, then continue on to Authentication & Permissions. Some of these videos were recorded on older Django releases, so check the official documentation if a detail differs on your install.
Covers creating a form class with forms.Form and ModelForm, rendering forms in templates, handling POST requests, validating and cleaning data, and displaying error messages.
Compares a regular Django form, a ModelForm, and a manually written HTML form, so you can choose the right approach for each situation.
Shows how to bind a form to a model using the ModelForm class.
Covers form validation, model validation, and writing custom validators.