djangodocs.org

1293 sections across all versions Narrow to Django 6.0 (current) →

BooleanField

Reference Form fields

classBooleanField(**kwargs)[source] : - Default widget: CheckboxInput - Empty value: False - Normalizes to: A Python True or False value. - Validates that the value is True (e.g. the check box is checked) if the field has required=True.

dev

FileField

Reference Form fields

- Can validate that non-empty file data has been bound to the form. - Error message keys: required, invalid, missing, empty, max_length

dev

Locale specific helpers

Topic guide Format localization

For country specific form fields, validation, and data formats that are not included in Django itself, consider using the django-localflavor package, which provides localized form fields and utilities for many countries and regions (documentation).

dev

BooleanField

Reference Form fields Built-in Field classes

classBooleanField(**kwargs)[source] : - Default widget: CheckboxInput - Empty value: False - Normalizes to: A Python True or False value. - Validates that the value is True (e.g. the check box is checked) if the field has required=True.

4.2 5.0 5.1 5.2 6.0

FileField

Reference Form fields Built-in Field classes

- Can validate that non-empty file data has been bound to the form. - Error message keys: required, invalid, missing, empty, max_length

4.2 5.0 5.1 5.2 6.0

Model forms

Topic guide Form handling with class-based views

Generic views really shine when working with models. These generic views will automatically create a ModelForm, so long as they can work out which model class to use: If the model attribute is given, that model class will be used.

dev

Model forms

Topic guide Form handling with class-based views

Generic views really shine when working with models. These generic views will automatically create a ModelForm, so long as they can work out which model class to use: If the model attribute is given, that model class will be used.

4.2 5.0 5.1 5.2 6.0

NON_FIELD_ERRORS

Reference Django exceptions

NON_FIELD_ERRORS ValidationErrors that don’t belong to a particular field in a form or model are classified as NON_FIELD_ERRORS. This constant is used as a key in dictionaries that otherwise map fields to their respective list of errors.

dev

NON_FIELD_ERRORS

Reference Django Exceptions Django Core ExceptionsValidationError

NON_FIELD_ERRORS ValidationErrors that don’t belong to a particular field in a form or model are classified as NON_FIELD_ERRORS. This constant is used as a key in dictionaries that otherwise map fields to their respective list of errors.

4.2 5.0 5.1 5.2 6.0

Built-in forms

Topic guide Using the Django authentication system Authentication in web requests

classBaseUserCreationForm[source] : A ModelForm for creating a new user. This is the recommended base class if you need to customize the user creation form. classPasswordChangeForm[source] : A form for allowing a user to change their password.

4.2 5.0 5.1 5.2 6.0

Bound and unbound forms

Reference The Forms API

A Form instance is either bound to a set of data, or unbound. If it’s bound to a set of data, it’s capable of validating that data and rendering the form as HTML with the data displayed in the HTML.

dev

Bound and unbound forms

Reference The Forms API

A Form instance is either bound to a set of data, or unbound. If it’s bound to a set of data, it’s capable of validating that data and rendering the form as HTML with the data displayed in the HTML.

4.2 5.0 5.1 5.2 6.0

ModelAdmin methods

Reference The Django admin site

ModelAdmin.formfield_for_manytomany(db_field,request,**kwargs) : Like the formfield_for_foreignkey method, the formfield_for_manytomany method can be overridden to change the default formfield for a many to many field.

dev

Writing validators

Reference Validators

A validator is a callable that takes a value and raises a ValidationError if it doesn’t meet some criteria. Validators can be useful for reusing validation logic between different types of fields.

dev