djangodocs.org

711 sections in Django dev Search all versions →

prefetch_related()

Reference QuerySet API reference

This means that for a large QuerySet a large ‘IN’ clause could be generated, which, depending on the database, might have performance problems of its own when it comes to parsing or executing the SQL query.

Attributes

Reference Request and response objects

HttpRequest.body[source] : The raw HTTP request body as a bytestring. This is useful for processing data in different ways than conventional HTML forms: binary images, XML payload etc. For processing conventional form data, use HttpRequest.POST.

Attributes

Reference Request and response objects

HttpRequest.COOKIES : A dictionary containing all cookies. Keys and values are strings. HttpRequest.FILES : A dictionary-like object containing all uploaded files. Each key in FILES is the name from the <input type="file" name="">. Each value in FILES is an UploadedFile.

QueryDict objects

Reference Request and response objects

This is necessary because some HTML form elements, notably <select multiple>, pass multiple values for the same key. The QueryDicts at request.POST and request.GET will be immutable when accessed in a normal request/response cycle.

Methods

Reference Request and response objects

HttpResponse.__init__(content=b'',content_type=None,status=200,reason=None,charset=None,headers=None)[source] : Instantiates an HttpResponse object with the given page content, content type, and headers. HttpResponse.__setitem__(header,value) : Sets the given header name to the given value. Both header and value should be strings.

CSRF_COOKIE_AGE

Reference Settings

Without persistent cookies, the form submission would fail in this case.

CSRF_COOKIE_DOMAIN

Reference 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

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

You can set this to None to disable the check. Applications that are expected to receive unusually large form posts should tune this setting. Under ASGI, the entire request may be spooled to disk before this limit is enforced.

Reference 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.

csp_nonce_attr

Reference Built-in template tags and filters

… object as the argument, renders its assets with the CSP nonce applied to each <script> and <link> element: In both forms, if the context processor is not configured, assets are rendered without a nonce attribute. See Nonce usage for full …

get_static_prefix

Reference Built-in template tags and filters

… 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

… 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 …

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 NOTE: Django has a vibrant ecosystem.

A better solution

Topic guide Using mixins with class-based views

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.