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 an HttpResponse produced the given status_code and that text appears in its content.
Reference
GeoDjango Model API
Geometry Field Options
GeometryField.max_geom_collections This option is forwarded to the form field generated for this model field, bounding how many geometry collections may be contained in submitted WKB/WKT inputs before raising ValueError.
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.
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
Each field is available as an attribute of the form, using {{ form.name_of_field }} in a template.
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.
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.
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.
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.
Reference
Settings
Core Settings
Default: 100 The maximum number of files that may be received via POST in a multipart/form-data encoded request before a SuspiciousOperation (TooManyFiles) is raised. You can set this to None to disable the check.
Topic guide
Working with forms
HTML forms
GET and POST are the only HTTP methods to use when dealing with forms.
Topic guide
Creating forms from models
ModelForm
It is strongly recommended that you explicitly set all fields that should be edited in the form using the fields attribute.
Topic guide
Security in Django
In a cross-site scripting attack, malicious code in the form of a client-side script is injected into another user’s web browser, where it will be executed.
FAQ
FAQ: The admin
You’ve got several options. If you want to piggyback on top of an add/change form that Django automatically generates, you can attach arbitrary JavaScript modules to the page via the model’s class Admin js parameter.
How-to
How to use Django’s CSRF protection
Edge cases
There are cases when CsrfViewMiddleware.process_view may not have run before your view is run - 404 and 500 handlers, for example - but you still need the CSRF token in a form. Solution: use requires_csrf_token()
How-to
How to create custom model fields
Background theory
All of Django’s fields (and when we say fields in this document, we always mean model fields and not form fields) are subclasses of django.db.models.Field.
How-to
How to create custom model fields
Writing a field subclass
It’s used during model migrations to tell Django how to take an instance of your new field and reduce it to a serialized form - in particular, what arguments to pass to __init__() to recreate it.
How-to
How to create custom template tags and filters
Writing custom template tags
django.template.Library.inclusion_tag() Another common type of template tag is the type that displays some data by rendering another template. For example, Django’s admin interface uses custom template tags to display the buttons along the bottom of the “add/change” form pages.
Django documentation
Django offers a robust internationalization and localization framework to assist you in the development of applications for multiple languages and world regions: Overview | Internationalization | Localization | Localized web UI formatting and form input Time zones