djangodocs.org

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

Reference The Forms API Outputting forms as HTML

classErrorList(initlist=None,error_class=None,renderer=None,field_id=None)[source] : By default, forms use django.forms.utils.ErrorList to format validation errors. ErrorList is a list like object where initlist is the list of errors. In addition this class has the following attributes and methods.

4.2 5.0 5.1 5.2 6.0

TelInput

Reference Widgets Built-in widgetsWidgets handling input of text

New in Django 5.2. classTelInput[source] : - input_type: 'tel' - template_name: 'django/forms/widgets/tel.html' - Renders as: <input type="tel" ...>

5.2 6.0

CharField

Reference Model field reference Field types

The default form widget for this field is a TextInput. CharField has the following extra arguments: CharField.max_length : The maximum length (in characters) of the field. The max_length is enforced at the database level and in Django’s validation using MaxLengthValidator.

4.2 5.0 5.1 5.2 6.0

validate_max

Topic guide Formsets Validating the number of forms in a formset

If validate_max=True is passed to formset_factory(), validation will also check that the number of forms in the data set, minus those marked for deletion, is less than or equal to max_num.

4.2 5.0 5.1 5.2 6.0

validate_min

Topic guide Formsets Validating the number of forms in a formset

If validate_min=True is passed to formset_factory(), validation will also check that the number of forms in the data set, minus those marked for deletion, is greater than or equal to min_num.

4.2 5.0 5.1 5.2 6.0

Topic guide Creating forms from models Inline formsets

When overriding methods on InlineFormSet, you should subclass BaseInlineFormSet rather than BaseModelFormSet. For example, if you want to override clean(): See also Overriding clean() on a ModelFormSet. Then when you create your inline formset, pass in the optional argument formset:

4.2 5.0 5.1 5.2 6.0

Custom template options

Reference The Django admin site

Use the following options to override the default templates used by the ModelAdmin views: ModelAdmin.add_form_template : Path to a custom template, used by add_view(). ModelAdmin.change_form_template : Path to a custom template, used by change_view().

dev

InlineModelAdmin options

Reference The Django admin site

… and adds some of its own (the shared features are actually defined in the BaseModelAdmin superclass). The shared features are: form fieldsets fields formfield_overrides delete_confirmation_max_display exclude filter_horizontal filter_vertical ordering prepopulated_fields get_exclude() get_fieldsets() get_queryset() radio_fields readonly_fields view_on_site empty_value_display autocomplete_fields raw_id_fields formfield_for_choice_field() …

dev

Via the Python API

Reference The flatpages app

The flatpage form > used in the admin performs this validation check, and can be imported from > django.contrib.flatpages.forms.FlatpageForm and used in your own > views.

dev

django.contrib.postgres

Reference

This optional module contains model fields and form fields for a number of PostgreSQL specific data types. NOTE: Django is, and will continue to be, a database-agnostic web framework.

dev

Widgets

Reference

TIP: Widgets should not be confused with the form fields. Form fields deal with the logic of input validation > and are used directly in templates.

dev

Widget

Reference Widgets

`render(name,value,attrs=None,renderer=None)`[[source]](https://github.com/django/django/blob/main/django/forms/widgets.py#L373) : Renders a widget to HTML using the given renderer. If `renderer` is `None`, the renderer from the [`FORM_RENDERER`](../settings.md#std-setting-FORM_RENDERER) setting is used. `value_from_datadict(data,files,name)`[[source]](https://github.com/django/django/blob/main/django/forms/widgets.py#L387) : Given a dictionary of data and this widget’s name, returns the value of this widget.

dev

FileField

Reference Model field reference

This handles the storage and retrieval of your files. See Managing files for details on how to provide this object. The default form widget for this field is a ClearableFileInput.

dev

Validating objects

Reference Model instance reference

… as a whole - Model.clean() Validate the field uniqueness - Model.validate_unique() Validate the constraints - Model.validate_constraints() All four steps are performed when you call a model’s full_clean() method. When you use a ModelForm, the call to is_valid() will perform these …

dev

Field types

Topic guide Models

INTEGER, VARCHAR, TEXT). The default HTML widget to use when rendering a form field (e.g. <input type="text">, <select>). The minimal validation requirements, used in Django’s admin and in automatically-generated forms.

dev

Topic guide Creating forms from models

Just like with a ModelForm, by default the clean() method of a ModelFormSet will validate that none of the items in the formset violate the unique constraints on your model (either unique, unique_together or unique_for_date|month|year).

dev

InlineModelAdmin options

Reference The Django admin site InlineModelAdmin objects

The shared features are: form fieldsets fields formfield_overrides exclude filter_horizontal filter_vertical ordering prepopulated_fields get_fieldsets() get_queryset() radio_fields readonly_fields view_on_site empty_value_display autocomplete_fields raw_id_fields formfield_for_choice_field() formfield_for_foreignkey() formfield_for_manytomany() has_module_permission() The InlineModelAdmin class adds or customizes: InlineModelAdmin.model : The model which the inline is using.

4.2 5.0 5.1 5.2 6.0

Via the Python API

Reference The flatpages app How to add, change and delete flatpages

The flatpage form > used in the admin performs this validation check, and can be imported from > django.contrib.flatpages.forms.FlatpageForm and used in your own > views.

4.2 5.0 5.1 5.2 6.0

django.contrib.postgres

Reference

This optional module contains model fields and form fields for a number of PostgreSQL specific data types. NOTE: Django is, and will continue to be, a database-agnostic web framework.

4.2 5.0 5.1 5.2 6.0