djangodocs.org

694 sections in Django 5.2 Search all versions →

exclude

Reference Model forms Model form Meta API

ModelFormOptions.exclude : A tuple or list of model field names to be excluded from the form.

field_classes

Reference Model forms Model form Meta API

ModelFormOptions.field_classes : A dictionary that maps a model field name to a Field class, which overrides the form_class used in the model field’s Field.formfield() method.

fields

Reference Model forms Model form Meta API

ModelFormOptions.fields : A tuple or list of model field names to be included in the form. The value '__all__' can be used to specify that all fields should be included.

localized_fields

Reference Model forms Model form Meta API

ModelFormOptions.localized_fields : A tuple or list of model field names to be localized. The value '__all__' can be used to specify that all fields should be localized.

modelform_factory

Reference Model forms Model form factory 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.

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.

Specifying widgets

Reference Widgets

Whenever you specify a field on a form, Django will use a default widget that is appropriate to the type of data that is to be displayed.

Complex expressions

Reference Built-in template tags and filters Built-in tag referenceif

All of the above can be combined to form complex expressions. For such expressions, it can be important to know how the operators are grouped when the expression is evaluated - that is, the precedence rules.

Topic guide Formsets

Sometimes your form class takes custom parameters, like MyArticleForm. You can pass this parameter when instantiating the formset: The form_kwargs may also depend on the specific form instance. The formset base class provides a get_form_kwargs method.

Field data

Topic guide Working with forms More about Django Form classesMore on fields

Whatever the data submitted with a form, once it has been successfully validated by calling is_valid() (and is_valid() has returned True), the validated form data will be in the form.cleaned_data dictionary.

Assertions

Topic guide Testing tools Test cases features

SimpleTestCase.assertFormSetError(formset,form_index,field,errors,msg_prefix='')[source] : Asserts that the formset raises the provided list of errors when rendered. SimpleTestCase.assertContains(response,text,count=None,status_code=200,msg_prefix='',html=False)[source] : Asserts that a response produced the given status_code and that text appears in its content.

Widget classes

Reference GeoDjango Forms API Form widgets

OpenLayersWidget classOpenLayersWidget[source] : This is the default widget used by all GeoDjango form fields. template_name is gis/openlayers.html. OSMWidget classOSMWidget[source] : This widget uses an OpenStreetMap base layer to display geographic objects on. Attributes are:

help_text

Reference Model field reference Field options

Field.help_text Extra “help” text to be displayed with the form widget. It’s useful for documentation even if your field isn’t used on a form. Note that this value is not HTML-escaped in automatically-generated forms.

HTML forms

Topic guide Working with forms

In HTML, a form is a collection of elements inside <form>...</form> that allow a visitor to do things like enter text, select options, manipulate objects or controls, and so on, and then send that information back to the server.

Topic guide Working with forms Working with form templates

However, it can also be directly accessed from the field attribute on the form. For example: Complete <label> elements can also be generated using the label_tag(). For example:

Topic guide Working with forms Working with form templatesLooping over the form’s fields

If you’re manually laying out a form in a template, as opposed to relying on Django’s default form layout, you might want to treat <input type="hidden"> fields differently from non-hidden fields.

Uploading multiple files

Topic guide File Uploads Basic file uploads

If you want to upload multiple files using one form field, create a subclass of the field’s widget and set its allow_multiple_selected class attribute to True.

Handling pull requests

Internals Committing code

Since Django is hosted on GitHub, patches are provided in the form of pull requests. When committing a pull request, make sure each individual commit matches the commit guidelines described below.

Release cadence

Internals Django’s release process

Starting with Django 2.0, version numbers will use a loose form of semantic versioning such that each version following an LTS will bump to the next “dot zero” version. For example: 2.0, 2.1, 2.2 (LTS), 3.0, 3.1, 3.2 (LTS), etc.