0PricingLogin
Django Academy · Lesson

Defining a forms.Form

Declare fields and their widgets.

Why Forms Exist

A Django form turns messy user input into clean Python data, handling rendering and validation in one tidy place. 📝

Subclass forms.Form

You declare a form by subclassing forms.Form. Each class attribute you add becomes a field on that form.

from django import forms

class ContactForm(forms.Form):
    name = forms.CharField()

All lessons in this course

  1. Defining a forms.Form
  2. is_valid and cleaned_data
  3. Rendering Forms in Templates
  4. CSRF Protection and the POST Flow
← Back to Django Academy