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.
654 sections in Django 4.2 Search all versions →
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.
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.
Reference The form rendering API Built-in-template form renderers
classTemplatesSetting 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.
Reference Settings Core Settings Topical Index
FORM_RENDERER
Reference The Django admin site ModelAdmin objects
ModelAdmin.get_changelist_form(request,**kwargs) : Returns a ModelForm class for use in the Formset on the changelist page. To use a custom form, for example: ModelAdmin.get_changelist_formset(request,**kwargs) : Returns a ModelFormSet class for use on the changelist page if list_editable is used.
Reference PostgreSQL specific form fields and widgets Fields
classSimpleArrayField(base_field,delimiter=',',max_length=None,min_length=None) : A field which maps to an array. It is represented by an HTML <input>.
Reference The Forms API Outputting forms as HTMLDefault rendering
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.
Reference The Forms API Outputting forms as HTMLDefault rendering
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.
Reference The Forms API Outputting forms as HTMLDefault rendering
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.
Reference The Forms API Outputting forms as HTMLOutput styles
Form.template_name_div New in Django 4.1. The template used by as_div(). Default: 'django/forms/div.html'. Form.as_div() New in Django 4.1.
Reference The Forms API Outputting forms as HTMLOutput styles
Form.template_name_p The template used by as_p(). Default: 'django/forms/p.html'. Form.as_p() as_p() renders the form as a series of <p> tags, with each <p> containing one field:
Reference The Forms API Outputting forms as HTMLOutput styles
Form.template_name_ul The template used by as_ul(). Default: 'django/forms/ul.html'. Form.as_ul() as_ul() renders the form as a series of <li> tags, with each <li> containing one field.
Reference The Forms API Outputting forms as HTMLOutput styles
Form.template_name_table The template used by as_table(). Default: 'django/forms/table.html'. Form.as_table() as_table() renders the form as an HTML <table>:
Reference The Forms API Binding uploaded files to a form
Form.is_multipart() If you’re writing reusable views or templates, you may not know ahead of time whether your form is a multipart form or not.
Reference The Forms API
Form.prefix You can put several Django forms inside one <form> tag. To give each Form its own namespace, use the prefix keyword argument: The prefix can also be specified on the form class:
Reference Formset Functions
formset_factory(form,formset=BaseFormSet,extra=1,can_order=False,can_delete=False,max_num=None,validate_max=False,min_num=None,validate_min=False,absolute_max=None,can_delete_extra=True,renderer=None) : Returns a FormSet class for the given form class.
Topic guide Working with forms Building a formBuilding a form in Django
Form data sent back to a Django website is processed by a view, generally the same view which published the form. This allows us to reuse some of the same logic.
Topic guide Working with forms More about Django Form classesMore on fields
Each form field has a corresponding Widget class, which in turn corresponds to an HTML form widget such as <input type="text">. In most cases, the field will have a sensible default widget.
Topic guide Creating forms from models ModelForm
The generated Form class will have a form field for every model field specified, in the order specified in the fields attribute. Each model field has a corresponding default form field.
Topic guide Creating forms from models ModelForm
The generated Form class will have a form field for every model field specified, in the order specified in the fields attribute. Each model field has a corresponding default form field.