djangodocs.org

717 sections in Django dev Search all versions →

ImageField

Reference Model field reference Field types

As with other fields, you can change the maximum length using the max_length argument. The default form widget for this field is a ClearableFileInput.

prefetch_related()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

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 StreamingHttpResponse 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 StreamingHttpResponse 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 FileResponse 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 Core Settings

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

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

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

csp_nonce_attr

Reference Built-in template tags and filters Built-in tag reference

… 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 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)[source] : 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:

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.