djangodocs.org

663 sections in Django 5.0 Search all versions →

CSRF_COOKIE_DOMAIN

Reference Settings Core Settings

It should be set to a string such as ".example.com" to allow a POST request from a form on one subdomain to be accepted by a view served from another subdomain.

CSRF_COOKIE_HTTPONLY

Reference Settings Core Settings

If you enable this and need to send the value of the CSRF token with an AJAX request, your JavaScript must pull the value from a hidden CSRF token form input instead of from the cookie.

Reference Settings Core Settings

Applications that are expected to receive unusually large form posts should tune this setting. The amount of request data is correlated to the amount of memory needed to process the request and populate the GET and POST dictionaries.

Reference Settings Core Settings

You can set this to None to disable the check. Applications that are expected to receive an unusually large number of form fields should tune this setting.

get_static_prefix

Reference Built-in template tags and filters Other tags and filters librariesstatic

… need more control over exactly where and how STATIC_URL is injected into the template, you can use the get_static_prefix template tag: There’s also a second form you can use to avoid extra processing if you need the value multiple times:

Conversion functions

Reference Unicode data General string handlingUseful utility functions

… its input to a string. The encoding parameter specifies the input encoding. (For example, Django uses this internally when processing form input data, which might not be UTF-8 encoded.) The strings_only parameter, if set to True, will result in Python …

Topic guide Using the Django authentication system Authentication in web requestsLimiting access to logged-in users

permission_required(perm,login_url=None,raise_exception=False) : It’s a relatively common task to check whether a user has a particular permission. For that reason, Django provides a shortcut for that case: the permission_required() decorator.:

All authentication views

Topic guide Using the Django authentication system Authentication in web requestsAuthentication Views

This prevents information leaking to potential attackers. If you want to provide an error message in this case, you can subclass [`PasswordResetForm`](#django.contrib.auth.forms.PasswordResetForm) and use the `form_class` attribute.

All authentication views

Topic guide Using the Django authentication system Authentication in web requestsAuthentication Views

classPasswordResetDoneView : URL name: password_reset_done classPasswordResetConfirmView : URL name: password_reset_confirm classPasswordResetCompleteView : URL name: password_reset_complete

Class-based views

Topic guide

For full details, see the class-based views reference documentation. Introduction to class-based views Built-in class-based generic views Form handling with class-based views Using mixins with class-based views

A better solution

Topic guide Using mixins with class-based views Avoid anything more complex

The number of subtle interactions between FormMixin and DetailView is already testing our ability to manage things. It’s unlikely you’d want to write this kind of class yourself.

Topic guide Using mixins with class-based views Avoid anything more complex

So why not do just that? We have a very clear division here: GET requests should get the DetailView (with the Form added to the context data), and POST requests should get the FormView. Let’s set up those views first.

Field options

Topic guide Models Fields

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. primary_key : If True, this field is the primary key for the model.

Field lookups

Topic guide Making queries Retrieving objects

Field lookups are how you specify the meat of an SQL WHERE clause. They’re specified as keyword arguments to the QuerySet methods filter(), exclude() and get(). Basic lookups keyword arguments take the form field__lookuptype=value. (That’s a double-underscore).

The pk lookup shortcut

Topic guide Making queries Retrieving objects

… equivalent: The use of pk isn’t limited to __exact queries – any query term can be combined with pk to perform a query on the primary key of a model: pk lookups also work across joins. For example, these three …

Topic guide Making queries Querying JSONField

… based on a given dictionary key, use that key as the lookup name: Multiple keys can be chained together to form a path lookup: If the key is an integer, it will be interpreted as an index transform in an …