djangodocs.org

711 sections in Django dev Search all versions →

Widget

Reference Widgets

classWidget(attrs=None)[source] : This abstract class cannot be rendered, but provides the basic attribute attrs. You may also implement or override the render() method on custom widgets.

MultiWidget

Reference Widgets

classMultiWidget(widgets,attrs=None)[source] : A widget that is composed of multiple widgets. MultiWidget works hand in hand with the MultiValueField.

DateField

Reference Model field reference

If you want to be able to modify this field, set the following instead of auto_now_add=True: The default form widget for this field is a DateInput. The admin adds a JavaScript calendar, and a shortcut for “Today”.

FileField

Reference Model field reference

See Managing files for details on how to provide this object. The default form widget for this field is a ClearableFileInput. Using a FileField or an ImageField (see below) in a model takes a few steps:

Field API reference

Reference Model field reference

classField[source] : Field is an abstract class that represents a database table column. Django uses fields to create the database table (db_type()), to map Python types to database (get_prep_value()) and vice-versa (from_db_value()).

Field API reference

Reference Model field reference

Fields often receive their values as a different type, either from serialization or from forms. `to_python(value)`[[source]](https://github.com/django/django/blob/main/django/db/models/fields/__init__.py#L799) : Converts the value into the correct Python object. It acts as the reverse of [`value_to_string()`](#django.db.models.Field.value_to_string), and is also called in [`clean()`](instances.md#django.db.models.Model.clean).

extra()

Reference QuerySet API reference

where / tables You can define explicit SQL WHERE clauses — perhaps to perform non-explicit joins — by using where. You can manually add tables to the SQL FROM clause by using tables.

Methods

Reference Request and response objects

This is similar to the user attribute but it works in async contexts. HttpRequest.get_host()[source] : Returns the originating host of the request using information from the HTTP_X_FORWARDED_HOST (if USE_X_FORWARDED_HOST is enabled) and HTTP_HOST headers, in that order.

Methods

Reference Request and response objects

HttpRequest.accepts(mime_type)[source] : Returns True if the request’s Accept header matches the mime_type argument: HttpRequest.read(size=None)[source] HttpRequest.readline()[source] HttpRequest.readlines()[source] HttpRequest.__iter__()[source] : Methods implementing a file-like interface for reading from an HttpRequest instance.

All authentication views

Topic guide Using the Django authentication system

logout_then_login(request,login_url=None)[source] : Logs a user out on POST requests, then redirects to the login page. classPasswordChangeView[source] : URL name: password_change classPasswordChangeDoneView[source] : URL name: password_change_done classPasswordResetView[source] : URL name: password_reset

Using class-based views

Topic guide Introduction to class-based views

… is worth noting that what your method returns is identical to what you return from a function-based view, namely some form of HttpResponse. This means that http shortcuts or TemplateResponse objects are valid to use inside a class-based view. While …

Topic guide Models

It doesn’t matter which model has the ManyToManyField, but you should only put it in one of the models – not both. Generally, ManyToManyField instances should go in the object that’s going to be edited on a form.

Topic guide Time zones

Most websites that care about time zones ask users in which time zone they live and store this information in the user’s profile. For anonymous users, they use the time zone of their primary audience or UTC.

Topic guide Translation

… within the translation block. Examples: You can use multiple expressions inside a single blocktranslate tag: NOTE: The previous more verbose format is still supported: > {% blocktranslate with book|title as book_t and author|title as author_t %} Other block tags (for …