djangodocs.org

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

SplitDateTimeField

Reference Form fields Slightly complex built-in Field classes

- Validates that the given value is a datetime.datetime or string formatted in a particular datetime format. - Error message keys: required, invalid, invalid_date, invalid_time

4.2 5.0 5.1 5.2 6.0

ModelMultipleChoiceField

Reference Form fields Fields which handle relationships

classModelMultipleChoiceField(**kwargs)[source] : - Default widget: SelectMultiple - Empty value: An empty QuerySet (self.queryset.none()) - Normalizes to: A QuerySet of model instances. - Validates that every id in the given list of values exists in the queryset.

4.2 5.0 5.1 5.2 6.0

Reference Form fields Fields which handle relationships

By default, ModelChoiceField and ModelMultipleChoiceField use ModelChoiceIterator to generate their field choices. When iterated, ModelChoiceIterator yields 2-tuple choices containing ModelChoiceIteratorValue instances as the first value element in each choice.

4.2 5.0 5.1 5.2 6.0

ModelChoiceIterator

Reference Form fields Fields which handle relationshipsIterating relationship choices

classModelChoiceIterator(field)[source] : The default class assigned to the iterator attribute of ModelChoiceField and ModelMultipleChoiceField. An iterable that yields 2-tuple choices from the queryset.

4.2 5.0 5.1 5.2 6.0

Paths as objects

Topic guide Form Assets (the Media class) Paths in asset definitions

Assets may also be object-based, using Script. Furthermore, these allow you to pass custom HTML attributes: If this Media definition were to be rendered, it would become the following HTML: Changed in Django 5.2: The object class Script was added.

5.2 6.0

Paths as objects

Topic guide Form Assets (the Media class) Paths in asset definitions

Asset paths may also be given as hashable objects implementing an __html__() method. The __html__() method is typically added using the html_safe() decorator. The object is responsible for outputting the complete HTML <script> or <link> tag content:

4.2 5.0 5.1

Jinja2

Reference The form rendering API

Templates for the built-in widgets are located in django/forms/jinja2 and installed apps can provide templates in a jinja2 directory. To use this backend, all the forms and widgets in your project and its third-party apps must have Jinja2 templates.

dev

Reference The form rendering API

This is a dictionary that contains values like: name value attrs is_hidden template_name Some widgets add further information to the context. For instance, all widgets that subclass Input defines widget['type'] and MultiWidget defines widget['subwidgets'] for looping purposes.

dev