djangodocs.org

1305 sections across all versions Narrow to Django 6.0 (current) →

Reference Widgets

In the following example, the years attribute is set for a SelectDateWidget: See the Built-in widgets for more information about which widgets are available and which arguments they accept.

4.2 5.0 5.1 5.2 6.0

Styling widget classes

Reference Widgets Customizing widget instances

In a nutshell, you will need to subclass the widget and either define a “Media” inner class or create a “media” property. These methods involve somewhat advanced Python programming and are described in detail in the Form Assets topic guide.

4.2 5.0 5.1 5.2 6.0

RadioSelect

Reference Widgets Built-in widgetsSelector and checkbox widgets

classRadioSelect[source] : - template_name: 'django/forms/widgets/radio.html' - option_template_name: 'django/forms/widgets/radio_option.html'

4.2 5.0 5.1 5.2 6.0

Query Expressions

Reference

There are a number of built-in expressions (documented below) that can be used to help you write queries. Expressions can be combined, or in some cases nested, to form more complex computations.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

Methods

Reference Request and response objects FileResponse objects

HttpRequest.get_full_path_info()[source] : Like get_full_path(), but uses path_info instead of path. HttpRequest.build_absolute_uri(location=None)[source] : Returns the absolute URI form of location. If no location is provided, the location will be set to request.get_full_path().

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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:

4.2 5.0 5.1 5.2 6.0

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 …

4.2 5.0 5.1 5.2 6.0

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:

4.2 5.0 5.1 5.2 6.0

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

4.2 5.0 5.1 5.2 6.0