djangodocs.org

694 sections in Django 5.2 Search all versions →

Attributes of BoundField

Reference The Forms API More granular output

BoundField.aria_describedby[source] : > New in Django 5.2. BoundField.auto_id[source] : The HTML ID attribute for this BoundField. Returns an empty string if Form.auto_id is False.

Attributes of BoundField

Reference The Forms API More granular output

BoundField.initial[source] : Use BoundField.initial to retrieve initial data for a form field. It retrieves the data from Form.initial if present, otherwise trying Field.initial. Callable values are evaluated. See Initial form values for more examples.

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.

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.

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'

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.

DateTimeField

Reference Model field reference Field types

Takes the same extra arguments as DateField. The default form widget for this field is a single DateTimeInput. The admin uses two separate TextInput widgets with JavaScript shortcuts. WARNING: Always use DateTimeField with a datetime.datetime > instance.

GenericIPAddressField

Reference Model field reference Field types

classGenericIPAddressField(protocol='both',unpack_ipv4=False,**options)[source] An IPv4 or IPv6 address, in string format (e.g. 192.0.2.30 or 2a02:42fe::4). The default form widget for this field is a TextInput.

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.

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

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

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.