Forms for Djangos
Django forms handle user input safely: a Form class declares fields, renders HTML, validates submitted data and cleans it into Python types, while a ModelForm builds the form directly from a model. The built-in admin site is a ready-made interface for managing model data, configured through ModelAdmin classes.
Stage: Django Core · Part of the Django roadmap · Last reviewed 19 November 2026
What to learn in Forms
- Define a Form with fields and custom validation in clean methods
- Build a ModelForm and save it to the database
- Render a form with CSRF protection in a template
- Display field errors and non-field errors to the user
- Register models in the admin and customise list display and filters
- Handle file uploads in a form
Forms interview questions
What does the CSRF token in a Django form do?
It protects against cross-site request forgery, where another site tricks a logged-in user's browser into submitting a request. Django checks that the token in the POST matches the one tied to the session, and rejects forged requests.
What is the difference between a Form and a ModelForm?
A Form defines its fields manually and is independent of the database. A ModelForm generates fields from a model and can save the instance directly with save(). Use ModelForm when the form edits a model, and Form for other input.
Where Forms fits in the Django roadmap
Forms belongs to the Django Core stage (beginner level), which takes about 20 hours. Project structure.
Other units in this stage
Back to the full Django roadmap