djangodocs.org

717 sections in Django dev Search all versions →

DateField

Reference Model field reference Field types

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 Field types

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 QuerySet APIMethods that return new QuerySets

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

Topic guide Using the Django authentication system Authentication in web requestsRedirecting unauthorized requests in class-based views

If your AUTH_USER_MODEL inherits from AbstractBaseUser or implements its own get_session_auth_hash() method, authenticated sessions will include the hash returned by this function. In the AbstractBaseUser case, this is an HMAC of the password field.

All authentication views

Topic guide Using the Django authentication system Authentication in web requestsAuthentication Views

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 FieldsRelationships

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 Concepts

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 Internationalization: in template code

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

Message files

Topic guide Translation Localization: how to create language files

NOTE: If you’re using Windows and need to install the GNU gettext utilities so > makemessages works, see gettext on Windows for more > information.

Making requests

Topic guide Testing tools The test client

Use the django.test.Client class to make requests. classClient(enforce_csrf_checks=False,raise_request_exception=True,json_encoder=DjangoJSONEncoder,*,headers=None,query_params=None,**defaults)[source] : A testing HTTP client. Takes several arguments that can customize behavior.