Settings¶
Warning
Be careful when you override settings, especially when the default value
is a non-empty list or dictionary, such as STATICFILES_FINDERS.
Make sure you keep the components required by the features of Django you
wish to use.
Core Settings¶
Here’s a list of settings available in Django core and their default values. Settings provided by contrib apps are listed below, followed by a topical index of the core settings. For introductory material, see the settings topic guide.
ABSOLUTE_URL_OVERRIDES¶
Default: {} (Empty dictionary)
A dictionary mapping "app_label.model_name" strings to functions that take
a model object and return its URL. This is a way of inserting or overriding
get_absolute_url() methods on a per-installation basis. Example:
ABSOLUTE_URL_OVERRIDES = {
"blogs.blog": lambda o: "/blogs/%s/" % o.slug,
"news.story": lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug),
}
The model name used in this setting should be all lowercase, regardless of the case of the actual model class name.
ADMINS¶
Default: [] (Empty list)
A list of all the people who get code error notifications. When
DEBUG=False and AdminEmailHandler
is configured in LOGGING (done by default), Django emails these
people the details of exceptions raised in the request/response cycle.
Each item in the list should be a tuple of (Full name, email address). Example:
[("John", "[email protected]"), ("Mary", "[email protected]")]
ALLOWED_HOSTS¶
Default: [] (Empty list)
A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations.
Values in this list can be fully qualified names (e.g. 'www.example.com'),
in which case they will be matched against the request’s Host header
exactly (case-insensitive, not including port). A value beginning with a period
can be used as a subdomain wildcard: '.example.com' will match
example.com, www.example.com, and any other subdomain of
example.com. A value of '*' will match anything; in this case you are
responsible to provide your own validation of the Host header (perhaps in a
middleware; if so this middleware must be listed first in
MIDDLEWARE).
Django also allows the fully qualified domain name (FQDN) of any entries.
Some browsers include a trailing dot in the Host header which Django
strips when performing host validation.
If the Host header (or X-Forwarded-Host if
USE_X_FORWARDED_HOST is enabled) does not match any value in this
list, the django.http.HttpRequest.get_host() method will raise
SuspiciousOperation.
When DEBUG is True and ALLOWED_HOSTS is empty, the host
is validated against ['.localhost', '127.0.0.1', '[::1]'].
ALLOWED_HOSTS is also checked when running tests.
This validation only applies via get_host();
if your code accesses the Host header directly from request.META you
are bypassing this security protection.
APPEND_SLASH¶
Default: True
When set to True, if the request URL does not match any of the patterns
in the URLconf and it doesn’t end in a slash, an HTTP redirect is issued to the
same URL with a slash appended. Note that the redirect may cause any data
submitted in a POST request to be lost.
The APPEND_SLASH setting is only used if
CommonMiddleware is installed
(see Middleware). See also PREPEND_WWW.
CACHES¶
Default:
{
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
}
}
A dictionary containing the settings for all caches to be used with Django. It is a nested dictionary whose contents maps cache aliases to a dictionary containing the options for an individual cache.
The CACHES setting must configure a default cache;
any number of additional caches may also be specified. If you
are using a cache backend other than the local memory cache, or
you need to define multiple caches, other options will be required.
The following cache options are available.
BACKEND¶
Default: '' (Empty string)
The cache backend to use. The built-in cache backends are:
'django.core.cache.backends.db.DatabaseCache''django.core.cache.backends.dummy.DummyCache''django.core.cache.backends.filebased.FileBasedCache''django.core.cache.backends.locmem.LocMemCache''django.core.cache.backends.memcached.PyMemcacheCache''django.core.cache.backends.memcached.PyLibMCCache''django.core.cache.backends.redis.RedisCache'
You can use a cache backend that doesn’t ship with Django by setting
BACKEND to a fully-qualified path of a cache
backend class (i.e. mypackage.backends.whatever.WhateverCache).
KEY_FUNCTION¶
A string containing a dotted path to a function (or any callable) that defines how to compose a prefix, version and key into a final cache key. The default implementation is equivalent to the function:
def make_key(key, key_prefix, version):
return ":".join([key_prefix, str(version), key])
You may use any key function you want, as long as it has the same argument signature.
See the cache documentation for more information.
KEY_PREFIX¶
Default: '' (Empty string)
A string that will be automatically included (prepended by default) to all cache keys used by the Django server.
See the cache documentation for more information.
LOCATION¶
Default: '' (Empty string)
The location of the cache to use. This might be the directory for a file system cache, a host and port for a memcache server, or an identifying name for a local memory cache. e.g.:
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
"LOCATION": "/var/tmp/django_cache",
}
}
OPTIONS¶
Default: None
Extra parameters to pass to the cache backend. Available parameters vary depending on your cache backend.
Some information on available parameters can be found in the cache arguments documentation. For more information, consult your backend module’s own documentation.
TIMEOUT¶
Default: 300
The number of seconds before a cache entry is considered stale. If the value of
this setting is None, cache entries will not expire. A value of 0
causes keys to immediately expire (effectively “don’t cache”).
VERSION¶
Default: 1
The default version number for cache keys generated by the Django server.
See the cache documentation for more information.
CACHE_MIDDLEWARE_ALIAS¶
Default: 'default'
The cache connection to use for the cache middleware.
CACHE_MIDDLEWARE_KEY_PREFIX¶
Default: '' (Empty string)
A string which will be prefixed to the cache keys generated by the cache
middleware. This prefix is combined with the
KEY_PREFIX setting; it does not replace it.
CACHE_MIDDLEWARE_SECONDS¶
Default: 600
The default number of seconds to cache a page for the cache middleware.