djangodocs.org

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

Usage

Topic guide Templates Support for template engines

Template objects returned by get_template() and select_template() must provide a render() method with the following signature: Template.render(context=None,request=None) : Renders this template with a given context. Here’s an example of the search algorithm.

4.2 5.0 5.1 5.2 6.0

ChoiceField

Reference Form fields Built-in Field classes

classChoiceField(**kwargs)[source] : - Default widget: Select - Empty value: '' (an empty string) - Normalizes to: A string. - Validates that the given value exists in the list of choices. - Error message keys: required, invalid_choice

4.2 5.0 5.1 5.2 6.0

FilePathField

Reference Form fields Built-in Field classes

classFilePathField(**kwargs)[source] : - Default widget: Select - Empty value: '' (an empty string) - Normalizes to: A string. - Validates that the selected choice exists in the list of choices. - Error message keys: required, invalid_choice

4.2 5.0 5.1 5.2 6.0

ModelChoiceField

Reference Form fields Fields which handle relationships

classModelChoiceField(**kwargs)[source] : - Default widget: Select - Empty value: None - Normalizes to: A model instance. - Validates that the given id exists in the queryset. - Error message keys: required, invalid_choice

4.2 5.0 5.1 5.2 6.0

NullBooleanSelect

Reference Widgets Built-in widgetsSelector and checkbox widgets

classNullBooleanSelect[source] : - template_name: 'django/forms/widgets/select.html' - option_template_name: 'django/forms/widgets/select_option.html'

4.2 5.0 5.1 5.2 6.0

SelectMultiple

Reference Widgets Built-in widgetsSelector and checkbox widgets

classSelectMultiple[source] : - template_name: 'django/forms/widgets/select.html' - option_template_name: 'django/forms/widgets/select_option.html'

4.2 5.0 5.1 5.2 6.0

SelectDateWidget

Reference Widgets Built-in widgetsComposite widgets

classSelectDateWidget[source] : - template_name: 'django/forms/widgets/select_date.html'

4.2 5.0 5.1 5.2 6.0

extra()

Reference QuerySet API reference

extra(select=None,where=None,params=None,tables=None,order_by=None,select_params=None) Sometimes, the Django query syntax by itself can’t easily express a complex WHERE clause. For these edge cases, Django provides the extra() QuerySet modifier — a hook for injecting specific clauses into the SQL generated by a QuerySet.

dev

Topic guide Translation

If you want to select a language within a template, you can use the language template tag: While the first occurrence of “Welcome to our page” uses the current language, the second will always be in English.

dev

extra()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

extra(select=None,where=None,params=None,tables=None,order_by=None,select_params=None) Sometimes, the Django query syntax by itself can’t easily express a complex WHERE clause. For these edge cases, Django provides the extra() QuerySet modifier — a hook for injecting specific clauses into the SQL generated by a QuerySet.

4.2 5.0 5.1 5.2 6.0

Topic guide Translation Internationalization: in template code

If you want to select a language within a template, you can use the language template tag: While the first occurrence of “Welcome to our page” uses the current language, the second will always be in English.

4.2 5.0 5.1 5.2 6.0

CheckboxSelectMultiple

Reference Widgets Built-in widgetsSelector and checkbox widgets

classCheckboxSelectMultiple[source] : - template_name: 'django/forms/widgets/checkbox_select.html' - option_template_name: 'django/forms/widgets/checkbox_option.html' Like RadioSelect, you can loop over the individual checkboxes for the widget’s choices.

4.2 5.0 5.1 5.2 6.0

ChoiceField

Reference Form fields

classChoiceField(**kwargs)[source] : - Default widget: Select - Empty value: '' (an empty string) - Normalizes to: A string. - Validates that the given value exists in the list of choices. - Error message keys: required, invalid_choice

dev