djangodocs.org

669 sections in Django 5.1 Search all versions →

FormMixin

Reference Editing mixins

classdjango.views.generic.edit.FormMixin : A mixin class that provides facilities for creating and displaying forms.

Custom template options

Reference The Django admin site ModelAdmin objectsModelAdmin options

Use the following options to override the default templates used by the ModelAdmin views: ModelAdmin.add_form_template : Path to a custom template, used by add_view(). ModelAdmin.change_form_template : Path to a custom template, used by change_view().

Reference The Django admin site Overriding admin templates

Not every template in contrib/admin/templates/admin may be overridden per app or per model. The following can: actions.html app_index.html change_form.html change_form_object_tools.html change_list.html change_list_object_tools.html change_list_results.html date_hierarchy.html delete_confirmation.html object_history.html pagination.html popup_response.html prepopulated_fields_js.html search_form.html submit_line.html For those templates that cannot be overridden in this …

Output Properties

Reference GEOS API Geometry ObjectsGEOSGeometry

This output may be in the form of a string, buffer, or even another object. GEOSGeometry.ewkt : Returns the “extended” Well-Known Text of the geometry. This representation is specific to PostGIS and is a superset of the OGC WKT standard.

The messages framework

Reference

Quite commonly in web applications, you need to display a one-time notification message (also known as “flash message”) to the user after processing a form or some other types of user input.

Reference The messages framework Using messages in views and templates

classviews.SuccessMessageMixin : Adds a success message attribute to FormView based classes Example views.py: The cleaned data from the form is available for string interpolation using the %(field_name)s syntax.

Reference PostgreSQL specific model fields Range Fields

Django’s model and form field implementations use base classes below, and psycopg provides a register_range() to allow use of custom range types. classRangeField(**options) : Base class for model range fields. classdjango.contrib.postgres.forms.BaseRangeField : Base class for form range fields.

Reference The “sites” framework Example usage

… lets readers sign up to get notifications when news happens. It’s pretty basic: A reader signs up on a web form and immediately gets an email saying, “Thanks for your subscription.” It’d be inefficient and redundant to implement this sign …

Reference

… easy-to-use protection against Cross Site Request Forgeries. This type of attack occurs when a malicious website contains a link, a form button or some JavaScript that is intended to perform some action on your website, using the credentials of a …

Notes on field ordering

Reference The Forms API Outputting forms as HTML

In the as_p(), as_ul() and as_table() shortcuts, the fields are displayed in the order in which you define them in your form class. For example, in the ContactForm example, the fields are defined in the order subject, message, sender, cc_myself.

More granular output

Reference The Forms API

The as_p(), as_ul(), and as_table() methods are shortcuts – they’re not the only way a form object can be displayed. classBoundField[source] : Used to display HTML or access attributes for a single field of a Form instance.

Attributes of BoundField

Reference The Forms API More granular output

BoundField.auto_id[source] : The HTML ID attribute for this BoundField. Returns an empty string if Form.auto_id is False.

Methods of BoundField

Reference The Forms API More granular output

BoundField.legend_tag(contents=None,attrs=None,label_suffix=None)[source] : Calls label_tag() with tag='legend' to render the label with <legend> tags. This is useful when rendering radio and multiple checkbox widgets where <legend> may be more appropriate than a <label>. BoundField.render(template_name=None,context=None,renderer=None) : > New in Django 5.0.

Styling widget instances

Reference Widgets Customizing widget instances

… you will need to specify additional attributes at the time when the widget object is instantiated and assigned to a form field (and perhaps add some rules to your CSS files). For example, take the following form: This form will …

Select

Reference Widgets Built-in widgetsSelector and checkbox widgets

classSelect[source] : - template_name: 'django/forms/widgets/select.html' - option_template_name: 'django/forms/widgets/select_option.html' - Renders as: <select><option ...>...</select>

Reference Middleware Available middleware

classCsrfViewMiddleware[source] Adds protection against Cross Site Request Forgeries by adding hidden form fields to POST forms and checking requests for the correct value. See the Cross Site Request Forgery protection documentation.

BigIntegerField

Reference Model field reference Field types

classBigIntegerField(**options)[source] A 64-bit integer, much like an IntegerField except that it is guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807. The default form widget for this field is a NumberInput.

BooleanField

Reference Model field reference Field types

classBooleanField(**options)[source] A true/false field. The default form widget for this field is CheckboxInput, or NullBooleanSelect if null=True. The default value of BooleanField is None when Field.default isn’t defined.

FloatField

Reference Model field reference Field types

The default form widget for this field is a NumberInput when localize is False or TextInput otherwise. NOTE: The FloatField class is sometimes mixed up with the > DecimalField class.

TextField

Reference Model field reference Field types

The default form widget for this field is a Textarea. If you specify a max_length attribute, it will be reflected in the Textarea widget of the auto-generated form field. However it is not enforced at the model or database level.