djangodocs.org

713 sections in Django 6.0 Search all versions →

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

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.

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

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.

Topic guide Models FieldsRelationships

… you are using an intermediate model, you can also query on its attributes: If you need to access a membership’s information you may do so by directly querying the Membership model: Another way to access the same information is by …