djangodocs.org

694 sections in Django 5.2 Search all versions →

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.

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.

TimeField

Reference Model field reference Field types

classTimeField(auto_now=False,auto_now_add=False,**options)[source] A time, represented in Python by a datetime.time instance. Accepts the same auto-population options as DateField. The default form widget for this field is a TimeInput. The admin adds some JavaScript shortcuts.

Arguments

Reference Model field reference Relationship fieldsManyToManyField

ForeignKey.related_name : The name to use for the relation from the related object back to this one. It’s also the default value for related_query_name (the name to use for the reverse filter name from the target model).

STATIC_URL

Reference Settings Static Files

Default: None URL to use when referring to static files located in STATIC_ROOT. Example: "static/" or "https://static.example.com/" If not None, this will be used as the base path for asset definitions (the Media class) and the staticfiles app.

Reference

Standard HttpResponse objects are static structures. They are provided with a block of pre-rendered content at time of construction, and while that content can be modified, it isn’t in a form that makes it easy to perform modifications.