Django --- SETTINGS core configuration items
django core configuration items
Django's default configuration file that contains hundreds of configuration items, many of our 'life' are not met or need to be configured separately, these items when you need to go check the manual.
He stressed: the default value is not configured in settings.py file! Do not think settings.py
the value is the default configuration values, refer to the previous. settings.py
Is to use the django-admin startproject xxx
command, give us an additional created.
61 described below is a relatively common and important configuration items, sorted alphabetically, but the last part of the cache, auth, message, session, static configuration or the like.
- ADMINS
- ALLOWED_HOSTS
- APPEND_SLASH
- DATABASES
- DATE_FORMAT
- DATE_INPUT_FORMATS
- DATETIME_FORMAT
- DATETIME_INPUT_FORMATS
- DEBUG
- DEFAULT_CHARSET
- DEFAULT_CONTENT_TYPE
- DEFAULT_FROM_EMAIL
- DISALLOWED_USER_AGENTS
- EMAIL_BACKEND
- EMAIL_FILE_PATH
- EMAIL_HOST
- EMAIL_HOST_PASSWORD
- EMAIL_HOST_USER
- EMAIL_PORT
- EMAIL_SUBJECT_PREFIX
- EMAIL_USE_TLS
- EMAIL_USE_SSL
- EMAIL_SSL_CERTFILE
- EMAIL_SSL_KEYFILE
- EMAIL_TIMEOUT
- FILE_CHARSET
- INSTALLED_APPS
- LANGUAGE_CODE
- LANGUAGES
- LOCALE_PATHS
- LOGGING
- LOGGING_CONFIG
- MEDIA_ROOT
- MEDIA_URL
- MIDDLEWARE
- ROOT_URLCONF
- SECRET_KEY
- TEMPLATES
- TIME_ZONE
- USE_I18N
- USE_L10N
- USE_TZ
- WSGI_APPLICATION
- CACHES
- AUTHENTICATION_BACKENDS
- AUTH_USER_MODEL
- LOGIN_REDIRECT_URL
- LOGIN_URL
- LOGOUT_REDIRECT_URL
- PASSWORD_RESET_TIMEOUT_DAYS
- PASSWORD_HASHERS
- MESSAGE_LEVEL
- MESSAGE_STORAGE
- SESSION_COOKIE_AGE
- SESSION_COOKIE_NAME
- SESSION_ENGINE
- SESSION_EXPIRE_AT_BROWSER_CLOSE
- SITE_ID
- STATIC_ROOT
- STATIC_URL
- STATICFILES_DIRS
1. ADMINS
Default: [] (the empty list)
E-mail address list of all the people get the code error notifications. When DEBUG = False, and a view raises an exception, Django will give the list of people to send an e-mail message containing a complete anomaly. Each item in the list should be (full name, e-mail address) tuples. E.g:
[('John', '[email protected]'), ('Mary', '[email protected]')]
2. ALLOWED_HOSTS
Default: [] (the empty list)
This is a configuration item novice puzzling. The configuration items are included in the list of whom Django site may host / domain name services . That is, which hosts or IP Django can access the server! List of all elements is the relationship of co-existence, impure in conflict, priorities and relationships exclusion.
Value in the list may be 'localhost', 'www.example.com' or '.example.com' form of the domain name.
It may be an IP address, such as: '137.2.4.1', '192.168.1.1', '0.0.0.0', '127.0.0.1'
Can also be a wildcard '*' means all external host can access Django. But this is a security risk, do not use the online environment.
For '0.0.0.0', a host on the LAN can access Django.
When DEBUG is True and 'allowed_hosts to' empty, the default configuration is equivalent to: [ 'localhost', '127.0.0.1', '[:: 1]'].
3. APPEND_SLASH
Default value: True
When set to True, the requested URL if no matched disposed inside the URLconf any one URL, and not with '/' (slash) is completed, the request is redirected to the requested URL to add '/' a URL address. Note that redirection may lead to loss of data submitted by POST.
Popular explanation is that if you forget when writing the url to add a slash at the end, Django will default to help you add! Please try to keep the default value!
'APPEND_SLASH' setting is enabled only when 'CommonMiddleware' middleware installed.
Such as: Default is (127.0.0.1:8000/ path), is set to true (127.0.0.1:8000 path)
4. DATABASES
Default: {} (empty dictionary)
The entry contains the configuration settings for all databases used by Django project. This is a nested dictionary.
DATABASES default settings must configure a database, and specify any number of other database (can not).
The simplest configuration is to use SQLite databases, Python and Django built-in support for SQLite databases, without any additional installation and plug-ins, as follows:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase',
# 或者'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
Since SQLite local database in Django project, generally or in the root directory of your Django project, in the form of a file, no problem user name, password, IP, port, so the configuration is relatively simple.
When connecting to other back-end database, such as MySQL, Oracle or PostgreSQL, you must provide more connection parameters. The following Examples PostgreSQL:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Here is DATABASES internal configuration items:
- ATOMIC_REQUESTS
Default value: False
Atomic transaction request.
- AUTOCOMMIT
Default value: True
Automatic commit.
- ENGINE
Default: '' (the empty string)
The most important configuration items! Specifies the database backend to use. There are built-in database backend name:
'django.db.backends.postgresql'
'django.db.backends.mysql'
'django.db.backends.sqlite3'
'django.db.backends.oracle'
- HOST
Default: '' (the empty string)
Host database resides. The value can be a host name, IP address, and socket path. Empty string representation localhost. SQLite not need to configure this option.
If this value with a slash ( '/') at the beginning and you are using MySQL, MySQL connects via Unix socket. like this:
"HOST": '/var/run/mysql'
- NAME
Default: '' (the empty string)
Use the database name. For SQLite, which is the full path of the database file. When specifying the path, always use forward slashes, even on Windows (eg: 'C: /homes/user/mysite/sqlite3.db').
But for MySQL and other databases, NAME refers to the database system in a specific database, Django is no ability to automatically create a database in MySQL, it can only create a data table by model. So you need through a variety of data from the client, to create a good database in MySQL advance Django project needs, use the command 'CREATE DATABASE mysite CHARACTER SET utf8;', mysite is your database name, be sure to specify character encoding is utf8!
- CONN_MAX_AGE
Default: 0
Survival time database connection, in seconds. 0 to turn off at the end of each connected to a database request, None indicates an infinite persistent connection.
- OPTIONS
Default: {} (empty default dictionary)
Connect additional parameters to use when the database. Available parameters related to your back-end database.
- PASSWORD
Default: '' (the empty string)
Password to use when connected to a database. SQLite does not require this option.
- PORT
Default: '' (the empty string)
Port used by the database. Empty string indicates the default port. SQLite does not require this option. MySQL is generally 3306.
- TIME_ZONE
Default value: None
Time zone used in the database.
- USER
Default: '' (the empty string)
User name to use when connecting to the database. SQLite does not require this option.
- TEST
Default: {} (empty default dictionary)
Test database configuration used.
The following is an example of the configuration of the database test:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'USER': 'mydatabaseuser',
'NAME': 'mydatabase',
'TEST': {
'NAME': 'mytestdatabase',
},
},
}
5. DATE_FORMAT
Default: 'N j, Y' (e.g.: Feb 4, 2003.)
The default system display format of the date field.
6. DATE_INPUT_FORMATS
Defaults:
[
'%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06'
'%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006'
'%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006'
'%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006'
'%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006'
]
Date input field will be able to accept the list format data. Format will be tried in order, using the first valid format.
7. DATETIME_FORMAT
Default: 'N j, Y, P' (e.g. Feb. 4, 2003, 4 pm)
Datetime fields default format display system.
8. DATETIME_INPUT_FORMATS
Defaults:
[
'%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'
'%Y-%m-%d', # '2006-10-25'
'%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', # '10/25/2006'
'%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'
'%m/%d/%y', # '10/25/06'
]
A list format input data to be accepted in the field datetime. Format will be tried in order, using the first valid format.
9. DEBUG
Default value: False
On / off debug mode. One of the most important settings! The default value is False, you read it right! Just in settings.py, it also helped us set to True, and opened debug mode, to facilitate developers and testers! When deployed online site must be set to False.
Debug mode can show the details of the error page. If your application generates an exception, Django will display retrospective details, including a number of environmental variables metadata, such as Django all the currently defined.
As a safety consideration, debug information will not list the contents of configuration items of the following keywords, such as SECRET_KEY:
'API'
'KEY'
'PASS'
'SECRET'
'SIGNATURE'
'TOKEN'
Note the use of containing matching, that is to say as long as these configuration items will appear substring matches. For example, 'PASS' can be matched PASSWORD, 'TOKEN' will also match TOKENIZED like.
Finally Again, if DEBUG is False, you also need to set 'ALLOWED_HOSTS' as well as static files correctly. Error setting will result in a return "Bad Request (400)" for all requests.
10. DEFAULT_CHARSET
Default: 'utf-8'
HttpResponse response object's default character set.
11. DEFAULT_CONTENT_TYPE
Default: 'text / html'
The default content type HttpResponse object.
12. DEFAULT_FROM_EMAIL
Default value: 'webmaster @ localhost'
The default e-mail address, that is the sender.
13. DISALLOWED_USER_AGENTS
Default: [] (the empty list)
This is a list compiled a regular expression object. Which does not allow access to any page of the User-Agent string represents. In other words, if a User-Agent request of the property, is any one of the configuration items to the regular expression matching, then the request will be blocked. Commonly used to deal with robots and spiders. CommonMiddleware need middleware support.
14. EMAIL_BACKEND
Default: 'django.core.mail.backends.smtp.EmailBackend'
The back-end for sending mail.
15. EMAIL_FILE_PATH
Default: not specified
Mail backend used to save the output files.
16. EMAIL_HOST
Default: 'localhost'
Send mail using the host.
17. EMAIL_HOST_PASSWORD
Default: '' (the empty string)
'EMAIL_HOST' The password for the SMTP server.
18. EMAIL_HOST_USER
Default: '' (the empty string)
Username 'EMAIL_HOST''s SMTP server.
19. EMAIL_PORT
Default: 25
Port 'EMAIL_HOST' of the SMTP server.
20. EMAIL_SUBJECT_PREFIX
Default: '[Django]'
Use 'django.core.mail.mail_admins' or 'django.core.mail.mail_managers' prefix in the subject line of the email sent.
21. EMAIL_USE_TLS
Default value: False
Whether to use TLS (secure) connection to the SMTP server. For explicit TLS connection, typically port 587.
22. EMAIL_USE_SSL
Default value: False
Whether implicit TLS (safety) at the time of communicating with the SMTP server connection. In most e-mail document, this type of connection is called TLS SSL. It is often used on port 465.
Note: Tencent home qq-mail service, you need to use the ssl secure link 465 port!
Please note that, 'EMAIL_USE_TLS' and 'EMAIL_USE_SSL' are mutually exclusive, so only one of which is set to True.
23. EMAIL_SSL_CERTFILE
Default value: None
If 'EMAIL_USE_SSL' or 'EMAIL_USE_TLS' is True, the certificate chain can optionally specify a file path PEM format to be used for SSL connections.
24. EMAIL_SSL_KEYFILE
Default value: None
If 'EMAIL_USE_SSL' or 'EMAIL_USE_TLS is True', the private key can optionally specify a file path PEM format to be used for SSL connections.
25. EMAIL_TIMEOUT
Default value: None
Send e-mail timeout.
26. FILE_CHARSET
Default: 'utf-8'
Used when reading the file from disk character encoding. Including template files and initial SQL data files.
No special requirements, please do not modify it.
27. INSTALLED_APPS
Default: [] (the empty list)
Django core configuration item!
List app Django project enabled the current. Each element should be a path dotted Python, a string:
Within the project each enabled app, Django includes a built-in contrib must be registered in the list, or create data tables, functions, etc. can not be invoked.
A typical configuration is as follows:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app1',
'app2',
]
It proposed to add a comma after the last element.
28. LANGUAGE_CODE
Default: 'en-us'
The current language used by the project. The default is English. Chinese is a 'zh-hans', do not write anything else, such as 'chinese' like!
'USE_I18N' must be set to True to make 'LANGUAGE_CODE' effect.
29. LANGUAGES
Default: a list of all available languages.
This configuration represents the available language item, (language code, the language name) Two list of tuples, e.g. :( 'ja', 'Japanese').
In general, the default value is sufficient. If the custom settings LANGUAGES, may be used 'ugettext_lazy ()' function name tag language translation strings.
The following is an example setup file:
from django.utils.translation import ugettext_lazy as _
LANGUAGES = [
('de', _('German')),
('en', _('English')),
]
30. LOCALE_PATHS
Default: [] (the empty list)
Find a list of directories Django translation of documents, such as:
LOCALE_PATHS = [
'/home/www/project/common_files/locale',
'/var/local/translations/locale',
]
Django will look in the directory containing the actual path of these translation files.
31. LOGGING
Default: logging configuration dictionary.
Log configuration information.
32. LOGGING_CONFIG
Default: 'logging.config.dictConfig'
Callable path for entry to configure logging in Django project.
33. MEDIA_ROOT
Default: '' (the empty string)
Users to upload files, directory, and the absolute path of the file system. That is where the instructions to upload files into.
For example: "/var/www/example.com/media/"
Warning: MEDIA_ROOT and STATIC_ROOT must be set to a different value.
34. MEDIA_URL
Default: '' (the empty string)
'MEDIA_URL' point 'MEDIA_ROOT' designated media file for managing the saved file. When the URL is set to non-null value, it must slash "/" end.
If you plan to use the template '{{MEDIA_URL}}', you must add the 'django.template.context_processors.media' in the TEMPLATES 'context_processors' setting.
Warning: 'MEDIA_URL' and 'STATIC_URL' must be set to a different value.
35. MIDDLEWARE
Default value: None
New features in Django1.10. To use the middleware list. The new project Django-admin command created, settings.py file by default will add a series of built-in Django middleware MIDDLEWARE configuration items, we like to keep it unchanged.
36. ROOT_URLCONF
Default: not specified
A string representing the full Python root URLconf introduction path. For example: "mydjangoapps.urls".
Each request can override it, by providing the HTTP request urlconf HttpRequest object attributes. But not idle, do not particularly set, use the default values just fine.
37. SECRET_KEY
Default: '' (the empty string)
Django current key projects instance. For providing a cryptographic signature, it is a unique and unpredictable value. such as:
SECRET_KEY = '+$*n1_pkko%zaz3!lm8lg208@uj^qy3mcsuy+*ov%ikpvd5$rf'
Project through the 'django-admin startproject xxx' command to create, it will add a randomly generated 'SECRET_KEY' in the settings.py.
If you do not set 'SECRET_KEY', Django will not start.
Warning: Do not reveal the true value of this configuration item!
38. TEMPLATES
Default: [] (the empty list)
Django template system configuration-related. Each entry is a dictionary type data (similar DATABASE configuration) list, you can configure different templates.
Below is an example:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
},
]
The following options are available for all the back-end.
BACKEND:
Default: not specified
To use the template backend. Back-end built-in templates are:
'django.template.backends.django.DjangoTemplates'
'django.template.backends.jinja2.Jinja2'
By setting BACKEND fully qualified path (i.e. 'mypackage.whatever.Backend'), you can use the template provided by the rear end of a third party.
NAME:
Default: see below
Alias this particular template engine, an identifier, and in some cases for a specified selection engine for rendering. Aliases must be unique in all configured template engine.
When not provided, if the rear end is 'mypackage.whatever.Backend', then the default name 'whatever'.
DIRS:
Default: [] (the empty list)
Search template path list. Search engines will find the resource file template in accordance with the order of the list. Shortest path algorithm to find the exit that is, no longer looking down.
APP_DIRS
Default value: False
Are Templates Template search engine should look for the source file in the app has been installed. Recommendation remains open, that is set to True!
By the 'django-admin startproject xxx' command to create a Django project, which settings.py file 'APP_DIRS' has been set up to True.
OPTIONS:
Defaults:{}
Additional parameters passed to the template backend. Available parameters vary due to the back-end templates.
39. TIME_ZONE
默认: 'America / Chicago'
Time zone setting.
Note that this is not necessarily the value of the configuration item and the server's time zone is consistent. For example, on a server may have multiple Django sites, each site has a single time zone.
If you want to make China the time, which is Beijing, please assignment: 'TIME_ZONE =' Asia / Shanghai ''. Note that Shanghai, not Beijing, embarrassing!
When 'USE_TZ' is False, it becomes Django store all date and time data, using the time zone. When 'USE_TZ' When is True, it is Django template display time, date interpretation forms, using the time zone. So, usually we will USE_TZ also set to False!
Note: In a Windows environment, Django can not reliably alternately other time zones. If you're running Django on Windows, 'TIME_ZONE' must be set to match the time zone system.
40. USE_I18N
Default value: True
This is a Boolean value that specifies whether Django's translation system is turned on. If set to False, Django will make some optimizations, do not load the translation mechanism.
By the 'django-admin startproject xxx' command to create a Django project, which settings.py file 'USE_I18N' has been set up to True.
41. USE_L10N
Default value: False
A Boolean value used to determine whether to open the data localization. If this is set to True, Django will display numbers such as the current date and format for the locale.
By the 'django-admin startproject xxx' command to create a Django project, which settings.py file 'USE_L10N' has been set up to True.
42. USE_TZ
Default value: False
A Boolean value specifying whether the time specified in the time zone (TIME_ZONE) a. If it is True, Django will use the built-in time time zone; otherwise, Django will use local time.
By the 'django-admin startproject xxx' command to create a Django project, which settings.py file 'USE_TZ' has been set up to True.
If we set the TIME_ZONE became Asia / Shanghai, so be sure to also change the USE_TZ False!
43. WSGI_APPLICATION
Default value: None
Django's built-in server (e.g., the runserver) full path Python WSGI application object will be used.
Django WSGI protocol used to communicate with the outside.
By the 'django-admin startproject xxx' command to create a Django project, will automatically create a simple 'wsgi.py' module, which has a callable application variables, values WSGI_APPLICATION configuration item to point to this application variables.
The following are 'wsgi.py' source:
"""
WSGI config for mysite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application()
Here are some related subsystems or configuration tool framework
44. CACHES
Defaults:
{
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
A nested dictionary, containing all the settings you want to use cache system.
CACHES must configure a default set cache can also specify any number of additional buffers at the same time (or may not).
The following are important internal configuration items:
BACKEND:
Default: '' (the empty string)
To cache backend to use. Built-in caching backend 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.MemcachedCache'
'django.core.cache.backends.memcached.PyLibMCCache'
By setting BACKEND fully qualified path of the rear end of the cache type (e.g. mypackage.backends.whatever.WhateverCache), the rear end of a third party can use the cache. ).
LOCATION:
Default: '' (the empty string)
Location of the cache to be used, could be a file system cache directory server host and port cache memory, or just local memory cache identifying name. E.g:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
OPTIONS:
Default value: None
Additional parameters passed to the cache backend. Available parameters vary due to cache backend.
TIMEOUT:
Default: 300
The effective time of the cache. If this setting is None, the cache will never expire.
VERSION:
Default: 1
The default version of Django server generates a cache key.
45. AUTHENTICATION_BACKENDS
Default: [ 'django.contrib.auth.backends.ModelBackend']
List of authentication backend to use when trying to authenticate the user. Django comes with default Auth framework.
46. AUTH_USER_MODEL
Default: 'auth.User'
User default model used.
47. LOGIN_REDIRECT_URL
Default: '/ accounts / profile /'
After logging in, if 'contrib.auth.login' can not find the next view parameter, the request will be redirected to the URL.
48. LOGIN_URL
Default: '/ accounts / login /'
Login URL of the page.
49. LOGOUT_REDIRECT_URL
Default value: None
After using LogoutView View Log, the request is redirected URL. If set to None, redirection is performed.
50. PASSWORD_RESET_TIMEOUT_DAYS
Default: 3
Password Reset link, the validity period, the number of days. (Comma separated, is not it better to understand a little?) For 'django.contrib.auth' password reset function.
51. PASSWORD_HASHERS
Password hashing algorithm used.
default:
[
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.Argon2PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
]
When Django1.10, the hashers deleted from the defaults:
'django.contrib.auth.hashers.SHA1PasswordHasher'
'django.contrib.auth.hashers.MD5PasswordHasher'
'django.contrib.auth.hashers.UnsaltedSHA1PasswordHasher'
'django.contrib.auth.hashers.UnsaltedMD5PasswordHasher'
'django.contrib.auth.hashers.CryptPasswordHasher'
52. MESSAGE_LEVEL
Default value: messages.INFO
Set Django built-in messaging framework -message, the lowest level recorded message.
53. MESSAGE_STORAGE
默认值:'django.contrib.messages.storage.fallback.FallbackStorage'
Django control where to store the message data. Valid values are:
'django.contrib.messages.storage.fallback.FallbackStorage'
'django.contrib.messages.storage.session.SessionStorage'
'django.contrib.messages.storage.cookie.CookieStorage'
54. SESSION_COOKIE_AGE
Default: 1209600 (2 weeks)
Cookie expiration time of the session, in seconds.
55. SESSION_COOKIE_NAME
Default: 'sessionid'
Cookie session name to be used. Name at random, as long as the application of other different cookie names.
56. SESSION_ENGINE
Default: 'django.contrib.sessions.backends.db'
Use the rear end of the session, that is, save the session data is unknown. The engine has built-in support:
'django.contrib.sessions.backends.db'
'django.contrib.sessions.backends.file'
'django.contrib.sessions.backends.cache'
'django.contrib.sessions.backends.cached_db'
'django.contrib.sessions.backends.signed_cookies'
57. SESSION_EXPIRE_AT_BROWSER_CLOSE
Default value: False
Whether expired session when the user closes the browser.
58. SITE_ID
Default: not specified
The current site 'django_site' database table ID, an integer from 1 to start counting.
Many people do not know Django is to support multi-site running simultaneously.
Usually we have only one site, so I do not care about this option. If you run multiple sites simultaneously, each app is that you have to know which site or sites and services, which requires the SITE_ID parameters.
59. STATIC_ROOT
Default value: None
When set to False in DEBUG, that is, when the online environment, Django project in the static files (js \ css \ plugins) will not be used. This is the need to run 'python manage.py collectstatic', the unified collection of static files to a directory. STATIC_ROOT configuration is the absolute path to the directory.
Example: "/ var / www / example.com / static /"
This directory should be the beginning of an empty directory.
60. STATIC_URL
Default value: None
TrackBack URL to use when a static file is located in the STATIC_ROOT.
示例:"/static/"或"http://static.example.com/"
When the URL is set to non-null value, it must slash "/" end.
61. STATICFILES_DIRS
Default: [] (the empty list)
Define additional static file search address.
E.g:
STATICFILES_DIRS = [
"/home/special.polls.com/polls/static",
"/home/polls.com/polls/static",
"/opt/webfiles/common",
]
Note that even on Windows (eg "C: / Users / user / mysite / extra_static_content"), these paths should use Unix-style forward slashes.
If you really could not tell the difference between 'MEDIA_ROOT, MEDIA_URL, STATIC_ROOT, STATIC_URL and STATICFILES_DIRS', the following is a reference version of the set:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, "all_static_files")
MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace("\\", "/")
MEDIA_URL = '/media/'