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
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
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
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
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
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
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
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
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
Topic guide
Creating forms from models
ModelFormValidation on a ModelForm
Error messages defined at the form field level or at the form Meta level always take precedence over the error messages defined at the model field level.
4.2
5.0
5.1
5.2
6.0
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
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
Topic guide
Creating forms from models
You can override the clean() method on a model form to provide additional validation in the same way you can on a normal form.
dev
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
Topic guide
Creating forms from models
ModelFormValidation on a ModelForm
You can override the clean() method on a model form to provide additional validation in the same way you can on a normal form.
4.2
5.0
5.1
5.2
6.0
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
Reference
PostgreSQL specific form fields and widgets
classSplitArrayField(base_field,size,remove_trailing_nulls=False) : This field handles arrays by reproducing the underlying field a fixed number of times.
dev
Reference
PostgreSQL specific form fields and widgets
Fields
classSplitArrayField(base_field,size,remove_trailing_nulls=False) : This field handles arrays by reproducing the underlying field a fixed number of times.
4.2
5.0
5.1
5.2
6.0
Topic guide
Creating forms from models
Error messages defined at the form field level ( django.forms.Field.error_messages) or at the form Meta level always take precedence over the error messages defined at the model field level (django.db.models.Field.error_messages).
dev
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