- Settings
- Settings
- Core Settings
- ABSOLUTE_URL_OVERRIDES
- ADMINS
- ALLOWED_HOSTS
- APPEND_SLASH
- CACHES
- CACHE_MIDDLEWARE_ALIAS
- CACHE_MIDDLEWARE_KEY_PREFIX
- CACHE_MIDDLEWARE_SECONDS
- CSRF_COOKIE_AGE
- CSRF_COOKIE_DOMAIN
- CSRF_COOKIE_HTTPONLY
- CSRF_COOKIE_NAME
- CSRF_COOKIE_PATH
- CSRF_COOKIE_SAMESITE
- CSRF_COOKIE_SECURE
- CSRF_USE_SESSIONS
- CSRF_FAILURE_VIEW
- CSRF_HEADER_NAME
- CSRF_TRUSTED_ORIGINS
- DATABASES
- DATA_UPLOAD_MAX_MEMORY_SIZE
- DATA_UPLOAD_MAX_NUMBER_FIELDS
- DATA_UPLOAD_MAX_NUMBER_FILES
- DATABASE_ROUTERS
- DATE_FORMAT
- DATE_INPUT_FORMATS
- DATETIME_FORMAT
- DATETIME_INPUT_FORMATS
- DEBUG
- DEBUG_PROPAGATE_EXCEPTIONS
- DECIMAL_SEPARATOR
- DEFAULT_AUTO_FIELD
- DEFAULT_CHARSET
- DEFAULT_EXCEPTION_REPORTER
- DEFAULT_EXCEPTION_REPORTER_FILTER
- DEFAULT_FROM_EMAIL
- DEFAULT_INDEX_TABLESPACE
- DEFAULT_TABLESPACE
- DISALLOWED_USER_AGENTS
- EMAIL_BACKEND
- EMAIL_FILE_PATH
- EMAIL_HOST
- EMAIL_HOST_PASSWORD
- EMAIL_HOST_USER
- EMAIL_PORT
- EMAIL_SUBJECT_PREFIX
- EMAIL_USE_LOCALTIME
- EMAIL_USE_TLS
- EMAIL_USE_SSL
- EMAIL_SSL_CERTFILE
Settings
Settings
- Core Settings
- Auth
- Messages
- Sessions
- Sites
- Static Files
- Core Settings Topical Index
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", "john@example.com"), ("Mary", "mary@example.com")]
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 integer number of seconds to cache a page for the cache middleware.
CSRF_COOKIE_AGE
Default: 31449600 (approximately 1 year, in seconds)
The age of CSRF cookies, in seconds.
The reason for setting a long-lived expiration time is to avoid problems in the case of a user closing a browser or bookmarking a page and then loading that page from a browser cache. Without persistent cookies, the form submission would fail in this case.
Some browsers (specifically Internet Explorer) can disallow the use of persistent cookies or can have the indexes to the cookie jar corrupted on disk, thereby causing CSRF protection checks to (sometimes intermittently) fail. Change this setting to None to use session-based CSRF cookies, which keep the cookies in-memory instead of on persistent storage.
CSRF_COOKIE_DOMAIN
Default: None
The domain to be used when setting the CSRF cookie. This can be useful for easily allowing cross-subdomain requests to be excluded from the normal cross site request forgery protection. 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.
Please note that the presence of this setting does not imply that Django’s CSRF protection is safe from cross-subdomain attacks by default - please see the CSRF limitations section.
CSRF_COOKIE_HTTPONLY
Default: False
Whether to use HttpOnly flag on the CSRF cookie. If this is set to True, client-side JavaScript will not be able to access the CSRF cookie.
Designating the CSRF cookie as HttpOnly doesn’t offer any practical protection because CSRF is only to protect against cross-domain attacks. If an attacker can read the cookie via JavaScript, they’re already on the same domain as far as the browser knows, so they can do anything they like anyway. (XSS is a much bigger hole than CSRF.)
Although the setting offers little practical benefit, it’s sometimes required by security auditors.
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.
See SESSION_COOKIE_HTTPONLY for details on HttpOnly.
CSRF_COOKIE_NAME
Default: 'csrftoken'
The name of the cookie to use for the CSRF authentication token. This can be whatever you want (as long as it’s different from the other cookie names in your application). See Cross Site Request Forgery protection.
CSRF_COOKIE_PATH
Default: '/'
The path set on the CSRF cookie. This should either match the URL path of your Django installation or be a parent of that path.
This is useful if you have multiple Django instances running under the same hostname. They can use different cookie paths, and each instance will only see its own CSRF cookie.
CSRF_COOKIE_SAMESITE
Default: 'Lax'
The value of the SameSite flag on the CSRF cookie. This flag prevents the cookie from being sent in cross-site requests.
See SESSION_COOKIE_SAMESITE for details about SameSite.
CSRF_COOKIE_SECURE
Default: False
Whether to use a secure cookie for the CSRF cookie. If this is set to True, the cookie will be marked as “secure”, which means browsers may ensure that the cookie is only sent with an HTTPS connection.
CSRF_USE_SESSIONS
Default: False
Whether to store the CSRF token in the user’s session instead of in a cookie. It requires the use of django.contrib.sessions.
Storing the CSRF token in a cookie (Django’s default) is safe, but storing it in the session is common practice in other web frameworks and therefore sometimes demanded by security auditors.
Since the default error views require the CSRF token, SessionMiddleware must appear in MIDDLEWARE before any middleware that may raise an exception to trigger an error view (such as PermissionDenied) if you’re using CSRF_USE_SESSIONS. See Middleware ordering.
CSRF_FAILURE_VIEW
Default: 'django.views.csrf.csrf_failure'
A dotted path to the view function to be used when an incoming request is rejected by the CSRF protection. The function should have this signature:
def csrf_failure(request, reason=""): ...
where reason is a short message (intended for developers or logging, not for end users) indicating the reason the request was rejected. It should return an HttpResponseForbidden.
django.views.csrf.csrf_failure() accepts an additional template_name parameter that defaults to '403_csrf.html'. If a template with that name exists, it will be used to render the page.
CSRF_HEADER_NAME
Default: 'HTTP_X_CSRFTOKEN'
The name of the request header used for CSRF authentication.
As with other HTTP headers in request.META, the header name received from the server is normalized by converting all characters to uppercase, replacing any hyphens with underscores, and adding an 'HTTP_' prefix to the name. For example, if your client sends a 'X-XSRF-TOKEN' header, the setting should be 'HTTP_X_XSRF_TOKEN'.
CSRF_TRUSTED_ORIGINS
Default: [] (Empty list)
A list of trusted origins for unsafe requests (e.g. POST).
For requests that include the Origin header, Django’s CSRF protection requires that header match the origin present in the Host header.
For a secure unsafe request that doesn’t include the Origin header, the request must have a Referer header that matches the origin present in the Host header.
These checks prevent, for example, a POST request from subdomain.example.com from succeeding against api.example.com. If you need cross-origin unsafe requests, continuing the example, add 'https://subdomain.example.com' to this list (and/or http://... if requests originate from an insecure page).
The setting also supports subdomains, so you could add 'https://*.example.com', for example, to allow access from all subdomains of example.com.
DATABASES
Default: {} (Empty dictionary)
A dictionary containing the settings for all databases to be used with Django. It is a nested dictionary whose contents map a database alias to a dictionary containing the options for an individual database.
The DATABASES setting must configure a default database; any number of additional databases may also be specified.
The simplest possible settings file is for a single-database setup using SQLite. This can be configured using the following:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "mydatabase",
}
}
When connecting to other database backends, such as MariaDB, MySQL, Oracle, or PostgreSQL, additional connection parameters will be required. See the ENGINE setting below on how to specify other database types. This example is for PostgreSQL:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "mydatabase",
"USER": "mydatabaseuser",
"PASSWORD": "mypassword",
"HOST": "127.0.0.1",
"PORT": "5432",
}
}
The following inner options that may be required for more complex configurations are available:
ATOMIC_REQUESTS
Default: False
Set this to True to wrap each view in a transaction on this database. See Tying transactions to HTTP requests.
AUTOCOMMIT
Default: True
Set this to False if you want to disable Django’s transaction management and implement your own.
ENGINE
Default: '' (Empty string)
The database backend to use. The built-in database backends are:
'django.db.backends.postgresql''django.db.backends.mysql''django.db.backends.sqlite3''django.db.backends.oracle'
You can use a database backend that doesn’t ship with Django by setting ENGINE to a fully-qualified path (i.e. mypackage.backends.whatever).
HOST
Default: '' (Empty string)
Which host to use when connecting to the database. An empty string means localhost. Not used with SQLite.
If this value starts with a forward slash ('/') and you’re using MySQL, MySQL will connect via a Unix socket to the specified socket. For example:
"HOST": "/var/run/mysql"
If you’re using MySQL and this value doesn’t start with a forward slash, then this value is assumed to be the host.
If you’re using PostgreSQL, by default (empty HOST), the connection to the database is done through UNIX domain sockets (‘local’ lines in pg_hba.conf). If your UNIX domain socket is not in the standard location, use the same value of unix_socket_directory from postgresql.conf. If you want to connect through TCP sockets, set HOST to ‘localhost’ or ‘127.0.0.1’ (‘host’ lines in pg_hba.conf). On Windows, you should always define HOST, as UNIX domain sockets are not available.
NAME
Default: '' (Empty string)
The name of the database to use. For SQLite, it’s the full path to the database file. When specifying the path, always use forward slashes, even on Windows (e.g. C:/homes/user/mysite/sqlite3.db).
CONN_MAX_AGE
Default: 0
The lifetime of a database connection, as an integer of seconds. Use 0 to close database connections at the end of each request — Django’s historical behavior — and None for unlimited persistent database connections.
CONN_HEALTH_CHECKS
Default: False
If set to True, existing persistent database connections will be health checked before they are reused in each request performing database access. If the health check fails, the connection will be reestablished without failing the request when the connection is no longer usable but the database server is ready to accept and serve new connections (e.g. after database server restart closing existing connections).
OPTIONS
Default: {} (Empty dictionary)
Extra parameters to use when connecting to the database. Available parameters vary depending on your database backend.
Some information on available parameters can be found in the Database Backends documentation. For more information, consult your backend module’s own documentation.
PASSWORD
Default: '' (Empty string)
The password to use when connecting to the database. Not used with SQLite.
PORT
Default: '' (Empty string)
The port to use when connecting to the database. An empty string means the default port. Not used with SQLite.
TIME_ZONE
Default: None
A string representing the time zone for this database connection or None. This inner option of the DATABASES setting accepts the same values as the general TIME_ZONE setting.
When USE_TZ is True, reading datetimes from the database returns aware datetimes with the timezone set to this option’s value if not None, or to UTC otherwise.
When USE_TZ is False, it is an error to set this option.
- If the database backend doesn’t support time zones (e.g. SQLite, MySQL, Oracle), Django reads and writes datetimes in local time according to this option if it is set and in UTC if it isn’t.
Changing the connection time zone changes how datetimes are read from and written to the database.
* If Django manages the database and you don’t have a strong reason to do otherwise, you should leave this option unset. It’s best to store datetimes in UTC because it avoids ambiguous or nonexistent datetimes during daylight saving time changes. Also, receiving datetimes in UTC keeps datetime arithmetic simple — there’s no need to consider potential offset changes over a DST transition.
* If you’re connecting to a third-party database that stores datetimes in a local time rather than UTC, then you must set this option to the appropriate time zone. Likewise, if Django manages the database but third-party systems connect to the same database and expect to find datetimes in local time, then you must set this option.
- If the database backend supports time zones (e.g., PostgreSQL), then the database connection’s time zone is set to this value.
Although setting the TIME_ZONE option is very rarely needed, there are situations where it becomes necessary. Specifically, it’s recommended to match the general TIME_ZONE setting when dealing with raw queries involving date/time functions like PostgreSQL’s date_trunc() or generate_series(), especially when generating time-based series that transition daylight savings.
This value can be changed at any time, the database will handle the conversion of datetimes to the configured time zone.
However, this has a downside: receiving all datetimes in local time makes datetime arithmetic more tricky — you must account for possible offset changes over DST transitions.
Consider converting to local time explicitly with AT TIME ZONE in raw SQL queries instead of setting the TIME_ZONE option.
DISABLE_SERVER_SIDE_CURSORS
Default: False
Set this to True if you want to disable the use of server-side cursors with QuerySet.iterator(). Transaction pooling and server-side cursors describes the use case.
This is a PostgreSQL-specific setting.
USER
Default: '' (Empty string)
The username to use when connecting to the database. Not used with SQLite.
TEST
Default: {} (Empty dictionary)
A dictionary of settings for test databases; for more details about the creation and use of test databases, see The test database.
Here’s an example with a test database configuration:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"USER": "mydatabaseuser",
"NAME": "mydatabase",
"TEST": {
"NAME": "mytestdatabase",
},
},
}
The following keys in the TEST dictionary are available:
CHARSET
Default: None
The character set encoding used to create the test database. The value of this string is passed directly through to the database, so its format is backend-specific.
Supported by the PostgreSQL (postgresql) and MySQL (mysql) backends.
COLLATION
Default: None
The collation order to use when creating the test database. This value is passed directly to the backend, so its format is backend-specific.
Only supported for the mysql backend (see the MySQL manual for details).
DEPENDENCIES
Default: ['default'], for all databases other than default, which has no dependencies.
The creation-order dependencies of the database. See the documentation on controlling the creation order of test databases for details.
MIGRATE
Default: True
When set to False, migrations won’t run when creating the test database. This is similar to setting None as a value in MIGRATION_MODULES, but for all apps.
MIRROR
Default: None
The alias of the database that this database should mirror during testing. It depends on transactions and therefore must be used within TransactionTestCase instead of TestCase.
This setting exists to allow for testing of primary/replica (referred to as master/slave by some databases) configurations of multiple databases. See the documentation on testing primary/replica configurations for details.
NAME
Default: None
The name of database to use when running the test suite.
If the default value (None) is used with the SQLite database engine, the tests will use a memory resident database. For all other database engines the test database will use the name 'test_' + DATABASE_NAME.
See The test database.
TEMPLATE
This is a PostgreSQL-specific setting.
The name of a template (e.g. 'template0') from which to create the test database.
CREATE_DB
Default: True
This is an Oracle-specific setting.
If it is set to False, the test tablespaces won’t be automatically created at the beginning of the tests or dropped at the end.
CREATE_USER
Default: True
This is an Oracle-specific setting.
If it is set to False, the test user won’t be automatically created at the beginning of the tests and dropped at the end.
USER
Default: None
This is an Oracle-specific setting.
The username to use when connecting to the Oracle database that will be used when running tests. If not provided, Django will use 'test_' + USER.
PASSWORD
Default: None
This is an Oracle-specific setting.
The password to use when connecting to the Oracle database that will be used when running tests. If not provided, Django will generate a random password.
ORACLE_MANAGED_FILES
Default: False
This is an Oracle-specific setting.
If set to True, Oracle Managed Files (OMF) tablespaces will be used. DATAFILE and DATAFILE_TMP will be ignored.
TBLSPACE
Default: None
This is an Oracle-specific setting.
The name of the tablespace that will be used when running tests. If not provided, Django will use 'test_' + USER.
TBLSPACE_TMP
Default: None
This is an Oracle-specific setting.
The name of the temporary tablespace that will be used when running tests. If not provided, Django will use 'test_' + USER + '_temp'.
DATAFILE
Default: None
This is an Oracle-specific setting.
The name of the datafile to use for the TBLSPACE. If not provided, Django will use TBLSPACE + '.dbf'.
DATAFILE_TMP
Default: None
This is an Oracle-specific setting.
The name of the datafile to use for the TBLSPACE_TMP. If not provided, Django will use TBLSPACE_TMP + '.dbf'.
DATAFILE_MAXSIZE
Default: '500M'
This is an Oracle-specific setting.
The maximum size that the DATAFILE is allowed to grow to.
DATAFILE_TMP_MAXSIZE
Default: '500M'
This is an Oracle-specific setting.
The maximum size that the DATAFILE_TMP is allowed to grow to.
DATAFILE_SIZE
Default: '50M'
This is an Oracle-specific setting.
The initial size of the DATAFILE.
DATAFILE_TMP_SIZE
Default: '50M'
This is an Oracle-specific setting.
The initial size of the DATAFILE_TMP.
DATAFILE_EXTSIZE
Default: '25M'
This is an Oracle-specific setting.
The amount by which the DATAFILE is extended when more space is required.
DATAFILE_TMP_EXTSIZE
Default: '25M'
This is an Oracle-specific setting.
The amount by which the DATAFILE_TMP is extended when more space is required.
DATA_UPLOAD_MAX_MEMORY_SIZE
Default: 2621440 (i.e. 2.5 MB).
The maximum size in bytes that a request body may be before a SuspiciousOperation (RequestDataTooBig) is raised. The check is done when accessing request.body or request.POST and is calculated against the total request size excluding any file upload data. You can set this to None to disable the check. 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. Large requests could be used as a denial-of-service attack vector if left unchecked. Since web servers don’t typically perform deep request inspection, it’s not possible to perform a similar check at that level.
See also FILE_UPLOAD_MAX_MEMORY_SIZE.
DATA_UPLOAD_MAX_NUMBER_FIELDS
Default: 1000
The maximum number of parameters that may be received via GET or POST before a SuspiciousOperation (TooManyFields) is raised. 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.
The number of request parameters is correlated to the amount of time needed to process the request and populate the GET and POST dictionaries. Large requests could be used as a denial-of-service attack vector if left unchecked. Since web servers don’t typically perform deep request inspection, it’s not possible to perform a similar check at that level.
DATA_UPLOAD_MAX_NUMBER_FILES
Default: 100
The maximum number of files that may be received via POST in a multipart/form-data encoded request before a SuspiciousOperation (TooManyFiles) is raised. You can set this to None to disable the check. Applications that are expected to receive an unusually large number of file fields should tune this setting.
The number of accepted files is correlated to the amount of time and memory needed to process the request. Large requests could be used as a denial-of-service attack vector if left unchecked. Since web servers don’t typically perform deep request inspection, it’s not possible to perform a similar check at that level.
DATABASE_ROUTERS
Default: [] (Empty list)
The list of routers that will be used to determine which database to use when performing a database query.
See the documentation on automatic database routing in multi database configurations.
DATE_FORMAT
Default: 'N j, Y' (e.g. Feb. 4, 2003)
The default formatting to use for displaying date fields in any part of the system. Note that the locale-dictated format has higher precedence and will be applied instead. See allowed date format strings.
See also DATETIME_FORMAT, TIME_FORMAT and SHORT_DATE_FORMAT.
DATE_INPUT_FORMATS
Default:
[
"%Y-%m-%d", # '2006-10-25'
"%m/%d/%Y", # '10/25/2006'
"%m/%d/%y", # '10/25/06'
"%b %d %Y", # 'Oct 25 2006'
"%b %d, %Y", # 'Oct 25, 2006'
"%d %b %Y", # '25 Oct 2006'
"%d %b, %Y", # '25 Oct, 2006'
"%B %d %Y", # 'October 25 2006'
"%B %d, %Y", # 'October 25, 2006'
"%d %B %Y", # '25 October 2006'
"%d %B, %Y", # '25 October, 2006'
]
A list of formats that will be accepted when inputting data on a date field. Formats will be tried in order, using the first valid one. Note that these format strings use Python’s datetime module syntax, not the format strings from the date template filter.
The locale-dictated format has higher precedence and will be applied instead.
See also DATETIME_INPUT_FORMATS and TIME_INPUT_FORMATS.
DATETIME_FORMAT
Default: 'N j, Y, P' (e.g. Feb. 4, 2003, 4 p.m.)
The default formatting to use for displaying datetime fields in any part of the system. Note that the locale-dictated format has higher precedence and will be applied instead. See allowed date format strings.
See also DATE_FORMAT, TIME_FORMAT and SHORT_DATETIME_FORMAT.
DATETIME_INPUT_FORMATS
Default:
[
"%Y-%m-%d %H:%M:%S", # '2006-10-25 14:30:59'
"%Y-%m-%d %H:%M:%S.%f", # '2006-10-25 14:30:59.000200'
"%Y-%m-%d %H:%M", # '2006-10-25 14:30'
"%m/%d/%Y %H:%M:%S", # '10/25/2006 14:30:59'
"%m/%d/%Y %H:%M:%S.%f", # '10/25/2006 14:30:59.000200'
"%m/%d/%Y %H:%M", # '10/25/2006 14:30'
"%m/%d/%y %H:%M:%S", # '10/25/06 14:30:59'
"%m/%d/%y %H:%M:%S.%f", # '10/25/06 14:30:59.000200'
"%m/%d/%y %H:%M", # '10/25/06 14:30'
]
A list of formats that will be accepted when inputting data on a datetime field. Formats will be tried in order, using the first valid one. Note that these format strings use Python’s datetime module syntax, not the format strings from the date template filter. Date-only formats are not included as datetime fields will automatically try DATE_INPUT_FORMATS in last resort.
The locale-dictated format has higher precedence and will be applied instead.
See also DATE_INPUT_FORMATS and TIME_INPUT_FORMATS.
DEBUG
Default: False
A boolean that turns on/off debug mode.
Never deploy a site into production with DEBUG turned on.
One of the main features of debug mode is the display of detailed error pages. If your app raises an exception when DEBUG is True, Django will display a detailed traceback, including a lot of metadata about your environment, such as all the currently defined Django settings (from settings.py).
As a security measure, Django will not include settings that might be sensitive, such as SECRET_KEY. Specifically, it will exclude any setting whose name includes any of the following:
'API''KEY''PASS''SECRET''SIGNATURE''TOKEN'
Note that these are partial matches. 'PASS' will also match PASSWORD, just as 'TOKEN' will also match TOKENIZED and so on.
Still, note that there are always going to be sections of your debug output that are inappropriate for public consumption. File paths, configuration options and the like all give attackers extra information about your server.
It is also important to remember that when running with DEBUG turned on, Django will remember every SQL query it executes. This is useful when you’re debugging, but it’ll rapidly consume memory on a production server.
Finally, if DEBUG is False, you also need to properly set the ALLOWED_HOSTS setting. Failing to do so will result in all requests being returned as “Bad Request (400)”.
Note
The default settings.py file created by django-admin startproject sets DEBUG = True for convenience.
DEBUG_PROPAGATE_EXCEPTIONS
Default: False
If set to True, Django’s exception handling of view functions (handler500, or the debug view if DEBUG is True) and logging of 500 responses (django.request) is skipped and exceptions propagate upward.
This can be useful for some test setups. It shouldn’t be used on a live site unless you want your web server (instead of Django) to generate “Internal Server Error” responses. In that case, make sure your server doesn’t show the stack trace or other sensitive information in the response.
DECIMAL_SEPARATOR
Default: '.' (Dot)
Default decimal separator used when formatting decimal numbers.
Note that the locale-dictated format has higher precedence and will be applied instead.
See also NUMBER_GROUPING, THOUSAND_SEPARATOR and USE_THOUSAND_SEPARATOR.
DEFAULT_AUTO_FIELD
Default: 'django.db.models.AutoField'
Default primary key field type to use for models that don’t have a field with primary_key=True.
Migrating auto-created through tables
The value of DEFAULT_AUTO_FIELD will be respected when creating new auto-created through tables for many-to-many relationships.
Unfortunately, the primary keys of existing auto-created through tables cannot currently be updated by the migrations framework.
This means that if you switch the value of DEFAULT_AUTO_FIELD and then generate migrations, the primary keys of the related models will be updated, as will the foreign keys from the through table, but the primary key of the auto-created through table will not be migrated.
In order to address this, you should add a RunSQL operation to your migrations to perform the required ALTER TABLE step. You can check the existing table name through sqlmigrate, dbshell, or with the field’s remote_field.through._meta.db_table property.
Explicitly defined through models are already handled by the migrations system.
Allowing automatic migrations for the primary key of existing auto-created through tables may be implemented at a later date.
DEFAULT_CHARSET
Default: 'utf-8'
Default charset to use for all HttpResponse objects, if a MIME type isn’t manually specified. Used when constructing the Content-Type header.
DEFAULT_EXCEPTION_REPORTER
Default: 'django.views.debug.ExceptionReporter'
Default exception reporter class to be used if none has been assigned to the HttpRequest instance yet. See Custom error reports.
DEFAULT_EXCEPTION_REPORTER_FILTER
Default: 'django.views.debug.SafeExceptionReporterFilter'
Default exception reporter filter class to be used if none has been assigned to the HttpRequest instance yet. See Filtering error reports.
DEFAULT_FROM_EMAIL
Default: 'webmaster@localhost'
Default email address for automated correspondence from the site manager(s). This address is used in the From: header of outgoing emails and can take any format valid in the chosen email sending protocol.
This doesn’t affect error messages sent to ADMINS and MANAGERS. See SERVER_EMAIL for that.
DEFAULT_INDEX_TABLESPACE
Default: '' (Empty string)
Default tablespace to use for indexes on fields that don’t specify one, if the backend supports it (see Tablespaces).
DEFAULT_TABLESPACE
Default: '' (Empty string)
Default tablespace to use for models that don’t specify one, if the backend supports it (see Tablespaces).
DISALLOWED_USER_AGENTS
Default: [] (Empty list)
List of compiled regular expression objects representing User-Agent strings that are not allowed to visit any page, systemwide. Use this for bots/crawlers. This is only used if CommonMiddleware is installed (see Middleware).
EMAIL_BACKEND
Default: 'django.core.mail.backends.smtp.EmailBackend'
The backend to use for sending emails. For the list of available backends see Email backends.
EMAIL_FILE_PATH
Default: Not defined
The directory used by the file email backend to store output files.
EMAIL_HOST
Default: 'localhost'
The host to use for sending email.
See also EMAIL_PORT.
EMAIL_HOST_PASSWORD
Default: '' (Empty string)
Password to use for the SMTP server defined in EMAIL_HOST. This setting is used in conjunction with EMAIL_HOST_USER when authenticating to the SMTP server. If either of these settings is empty, Django won’t attempt authentication.
See also EMAIL_HOST_USER.
EMAIL_HOST_USER
Default: '' (Empty string)
Username to use for the SMTP server defined in EMAIL_HOST. If empty, Django won’t attempt authentication.
See also EMAIL_HOST_PASSWORD.
EMAIL_PORT
Default: 25
Port to use for the SMTP server defined in EMAIL_HOST.
EMAIL_SUBJECT_PREFIX
Default: '[Django] '
Subject-line prefix for email messages sent with django.core.mail.mail_admins or django.core.mail.mail_managers. You’ll probably want to include the trailing space.
EMAIL_USE_LOCALTIME
Default: False
Whether to send the SMTP Date header of email messages in the local time zone (True) or in UTC (False).
EMAIL_USE_TLS
Default: False
Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, generally on port 587. If you are experiencing hanging connections, see the implicit TLS setting EMAIL_USE_SSL.
EMAIL_USE_SSL
Default: False
Whether to use an implicit TLS (secure) connection when talking to the SMTP server. In most email documentation this type of TLS connection is referred to as SSL. It is generally used on port 465. If you are experiencing problems, see the explicit TLS setting EMAIL_USE_TLS.
Note that EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True.
EMAIL_SSL_CERTFILE
Default: None
If EMAIL_USE_SSL or EMAIL_USE_TLS is True, you can optionally specify the path to a PEM-formatted certificate chain file to use for the SSL connection.
(本文超出站点单文档体积上限,已按小节截断)
