djangodocs.org

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

render()

Reference The Forms API

Form.render(template_name=None,context=None,renderer=None) The render method is called by __str__ as well as the Form.as_div(), Form.as_table(), Form.as_p(), and Form.as_ul() methods.

dev

The low-level render API

Reference The form rendering API

The rendering of form templates is controlled by a customizable renderer class. A custom renderer can be specified by updating the FORM_RENDERER setting. It defaults to 'django.forms.renderers.DjangoTemplates'.

dev

DjangoTemplates

Reference The form rendering API

It loads templates first from the built-in form templates directory in django/forms/templates and then from the installed apps’ templates directories using the app_directories loader.

dev

TemplatesSetting

Reference The form rendering API

classTemplatesSetting[source] This renderer gives you complete control of how form and widget templates are sourced. It uses get_template() to find templates based on what’s configured in the TEMPLATES setting.

dev

Forms

Reference Settings

FORM_RENDERER USE_BLANK_CHOICE_DASH

dev

render()

Reference The Forms API Outputting forms as HTMLDefault rendering

Form.render(template_name=None,context=None,renderer=None) The render method is called by __str__ as well as the Form.as_div(), Form.as_table(), Form.as_p(), and Form.as_ul() methods.

4.2 5.0 5.1 5.2 6.0

DjangoTemplates

Reference The form rendering API Built-in-template form renderers

It loads templates first from the built-in form templates directory in django/forms/templates and then from the installed apps’ templates directories using the app_directories loader.

4.2 5.0 5.1 5.2 6.0

TemplatesSetting

Reference The form rendering API Built-in-template form renderers

classTemplatesSetting[source] This renderer gives you complete control of how form and widget templates are sourced. It uses get_template() to find templates based on what’s configured in the TEMPLATES setting.

4.2 5.0 5.1 5.2 6.0

modelform_factory

Reference Model Form Functions

modelform_factory(model,form=ModelForm,fields=None,exclude=None,formfield_callback=None,widgets=None,localized_fields=None,labels=None,help_texts=None,error_messages=None,field_classes=None)[source] : Returns a ModelForm class for the given model. You can optionally pass a form argument to use as a starting point for constructing the ModelForm.

4.2 5.0 5.1

modelformset_factory

Reference Model forms Model form factory functions

modelformset_factory(model,form=ModelForm,formfield_callback=None,formset=BaseModelFormSet,extra=1,can_delete=False,can_order=False,max_num=None,fields=None,exclude=None,widgets=None,validate_max=False,localized_fields=None,labels=None,help_texts=None,error_messages=None,min_num=None,validate_min=False,field_classes=None,absolute_max=None,can_delete_extra=True,renderer=None,edit_only=False)[source] : Returns a FormSet class for the given model class.

4.2 5.0 5.1 5.2 6.0

Jinja2

Reference The form rendering API Built-in-template form renderers

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.

4.2 5.0 5.1 5.2 6.0

template_name

Reference The Forms API

Form.template_name The name of the template rendered if the form is cast into a string, e.g. via print(form) or in a template via {{ form }}. By default, a property returning the value of the renderer’s form_template_name.

dev

get_context()

Reference The Forms API

Form.get_context() Return the template context for rendering the form. The available context is: form: The bound form. fields: All bound fields, except the hidden fields. hidden_fields: All hidden bound fields.

dev

template_name_label

Reference The Forms API

Form.template_name_label The template used to render a field’s <label>, used when calling BoundField.label_tag()/legend_tag(). Can be changed per form by overriding this attribute or more generally by overriding the default template, see also Overriding built-in form templates.

dev