[Django learning] Django foundation (1)

1. Document Structure (General)

MySite -------------------------------- project folder

|____Blog -----------------------------Application Module

| |______init__.py--------------------Python modular flags

| |____admin.py-------------Application background management

| |____apps.py------------------------

| |____migrations ---------------------The database migration module of the application

| | |___init__.py-------------------Python modular flags

| |____models.py----------------------Applied models

| |____tests.py-----------------------

| |____views.py-------------app's views

| |____urls.py------------------------Apply routing

| |____templates ------------Apply's view

| | |___temp1.html----------------------Template 1

| | |___temp1.html----------------------Template 2

|____manage.py

|____MySite---------------------------

| |______init__.py

| |______pycache__

| | |______init__.cpython-36.pyc

| | |____settings.cpython-36.pyc

| |____settings.py

| |____urls.py

| |____wsgi.py

2. Global configuration file ( setting.py)

1. Default settings
       If you don't need it, the Django settings file does not need to define any settings. Because each setting has a default value. These default values ​​are defined in django/conf/global_settings.py.

2. Use the rules of settings:

  Load default settings from global_settings.py. 
  Load user settings from the specified settings file, overriding default settings if needed.

3. See which settings you have changed The
  command python manage.py diffsettings shows how the current settings file differs from Django's default settings.

4. Use settings in your code
  By importing the variable you need from the module django.conf.settings, your code can access this variable. 

5. Settings should not be modified while the program is running

6. Regarding the security of
  settings.py Since the settings file contains sensitive information, like database passwords, etc., you should set its access rights very carefully. For example, you can only allow you and the WEB server user to read the file. In a This is especially important when sharing a hosting environment.

7. Available options

(1)ABSOLUTE_URL_OVERRIDES Default value: {} (empty dictionary)

  A dictionary mapping the "app_label.module_name" string to a function that takes a model object as a parameter and returns its URL. This is one way to override the get_absolute_url() method on an installation. Example:

ABSOLUTE_URL_OVERRIDES =

{
    'blogs.blogs': lambda o: "/blogs/%s/" % o.slug,
    'news.stories': lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug),
}
(2)ADMIN_FOR            默认值: () (空的tuple)

  For the admin-site settings module, if the current site is admin , it is a tuple of settings modules (in a format like 'foo.bar.baz'). The admin site is automatically updated in models, views, and template tags This setting is used in introspective documents.

(3) ADMIN_MEDIA_PREFIX Default value: '/media/'

  The URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a trailing slash.

(4)ADMINS Default: () (empty tuple)

  A tuple of 2-element tuples. Lists people who are entitled to receive code error notifications. When DEBUG=False, a view raises an exception, and Django will email these people detailed exception information. This tuple Each member of should be in this format: (Full name, e-mail address). Example:

  (('John','[email protected]'), ('Mary', ' [email protected]'))
(5)ALLOWED_INCLUDE_ROOTS Default: () (empty tuple)

  A tuple of strings that can only be accessed by Django in the form ``{% ssi %}`` for templates prefixed with an element in the list. For security reasons, not even the author of the template can access it when it shouldn't these files.

  For example, if ALLOWED_INCLUDE_ROOTS is ('/home/html', '/var/www'), then {% ssi /home/html/foo.txt %} will work, but {% ssi /etc/passwd % } But can't.

(6)APPEND_SLASH Default value: True

  Whether to add a trailing slash to the URL. This option only works if CommonMiddleware is installed. (See middleware documentation). See PREPEND_WWW.

(7)CACHE_BACKEND Default value: 'simple://'

  The cache used by the backend. See the cache docs.

(8)CACHE_MIDDLEWARE_KEY_PREFIX Default value: '' (empty string)

  The cache key prefix used by cache middleware. See cache docs.

(9) DATABASE_ENGINE Default value: 'postgresql'

  Database engine used by the backend: any of 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.

(10)DATABASE_HOST Default value: '' (empty string)

  The host where the database is located. An empty string means localhost. This is not required for SQLite. 

  If you are using MySQL and the value of this option starts with a slash ('/'), MySQL connects to the specified socket through a Unix socket. For example: DATABASE_HOST = '/var/run/mysql'

  If you are using MySQL and the value of this option does not start with a slash, then the value of this option is the name of the host.

(11)DATABASE_NAME Default value: '' (empty string)

  The database name to use. For SQLite, it must be the full pathname of a database file.

(12)DATABASE_PASSWORD Default value: '' (empty string)

  Password required to connect to the database. SQLite does not require this.

(13)DATABASE_PORT Default value: '' (empty string)

  The database port required to connect to the database. An empty string indicates the default port. This is not required for SQLite.

(14)DATABASE_USER default value: '' (empty string)

  The username required to connect to the database. SQLite does not require this.

(15)DATE_FORMAT Default: 'N j, Y' (eg Feb. 4, 2003)

  The default date format used for date fields in the Django admin change-list page, other parts of the system may also use this format. See allowed date format strings.

  See DATETIME_FORMAT and TIME_FORMAT.

(16)DATETIME_FORMAT Default: 'N j, Y, P' (eg Feb. 4, 2003, 4 pm)

  The default datetime format used for datetime fields in the Django admin change-list page, and may also be used by other parts of the system. See allowed date format strings.

See DATE_FORMAT and TIME_FORMAT.

(17)DEBUG Default value: False

A logical value that toggles debug mode

(18)DEFAULT_CHARSET Default value: 'utf-8'

  If a MIME type is not manually specified, the default charset will be applied to all HttpResponse objects. Use DEFAULT_CONTENT_TYPE to construct the Content-Type header.

(19)DEFAULT_CONTENT_TYPE Default value: 'text/html'

  If a MIME type is not manually specified, the default content type will be applied to all HttpResponse objects. Use DEFAULT_CHARSET to construct the Content-Type header.

(20)DEFAULT_FROM_EMAIL Default value:  'webmaster@localhost'

  The default e-mail mailbox for sending (auto-generated by the site) administrative mail.

(21)DISALLOWED_USER_AGENTS Default: () (empty tuple)

  A list of compiled regular expression objects representing some user agent strings. These user agents will be blocked from accessing any page in the system. Use this against page bots or web crawlers . This option is only useful if CommonMiddleware is installed (see middleware documentation).

(22)EMAIL_HOST Default value: 'localhost'

  The host used to send e-mails. See EMAIL_PORT.

(23)EMAIL_HOST_PASSWORD Default value: '' (empty string)

  The password used by the SMTP server as defined in EMAIL_HOST. If empty, Django will not attempt to authenticate. See EMAIL_HOST_USER.

(24)EMAIL_HOST_USER Default value: '' (empty string)

  The username used by the SMTP server defined in EMAIL_HOST. If empty, Django will not attempt to authenticate. See EMAIL_HOST_PASSWORD.

(25)EMAIL_PORT Default: 25

  The port number used by the SMTP server specified in EMAIL_HOST.

(26)EMAIL_SUBJECT_PREFIX Default value: '[Django] '

Subject prefix for mail  sent by django.core.mail.mail_admins or django.core.mail.mail_managers .

(27)ENABLE_PSYCO Default value: False

  If Psyco is enabled, Python code will be optimized using Pscyo. Requires the Psyco module.

(28)IGNORABLE_404_ENDS  默认值: ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')

  See IGNORABLE_404_STARTS.

(29)IGNORABLE_404_STARTS Default value: ('/cgi-bin/', '/_vti_bin', '/_vti_inf')

  A string tuple . URLs starting with elements in this tuple should be ignored by 404 e-mailers. See SEND_BROKEN_LINK_EMAILS and IGNORABLE_404_ENDS.

(30)INSTALLED_APPS Default: () (empty tuple)

  A tuple of strings containing all applications in this Django installation. Each string should be the full path name of a Python package containing the Django application, to which django-admin.py startapp will automatically add content.

(31)INTERNAL_IPS Default: () (empty tuple)

  A tuple (in string form) of ip addresses, which: when DEBUG is True, see the debug service notes

(32)LANGUAGE_CODE Default value: 'en-us'

  A string representing the default language. Must be in standard language format. For example, US English is "en-us". See the internationalization docs.

  LANGUAGES Default value: a tuple (content in all available languages). Currently its values ​​are:

LANGUAGES = (
    ('en', _('English')),

    ('zh-cn', _('Simplified Chinese')),
)
A 2-element tuple <tuple of the form (language code, language name)>. This setting is used to select the available languages. See the internationalization docs for details.

  Usually this default value is sufficient. Unless you intend to reduce the number of languages ​​provided, there is no need to change this setting.

(33) MANAGERS Default value: ADMINS (regardless of whether ADMINS has been set)

  A tuple in the same format as ADMINS, when SEND_BROKEN_LINK_EMAILS=True, these people are entitled to receive dead link notification messages.

(34)MEDIA_ROOT Default: '' (empty string)

  An absolute path to save media files . Example: "/home/media/media.lawrence.com/" See MEDIA_URL.

(35)MEDIA_URL Default: '' (empty string)

URL  to handle media services (media files from MEDIA_ROOT). Example: "http://media.lawrence.com"

(36)MIDDLEWARE_CLASSES Default value:

("django.contrib.sessions.middleware.SessionMiddleware",
 "django.contrib.auth.middleware.AuthenticationMiddleware",
 "django.middleware.common.CommonMiddleware",
 "django.middleware.doc.XViewMiddleware")
a django used A tuple of middleware class names . See middleware documentation.

(37)PREPEND_WWW Default value: False

  Whether to add the "www." prefix to domains without the "www." prefix. This option is valid if and only if CommonMiddleware is installed. (See middleware documentation). See APPEND_SLASH.

(38)ROOT_URLCONF Default value: Not defined

  A string representing the module name of your root URLconf . For example: "mydjangoapps.urls". See How Django handles a request.

(39)SECRET_KEY Default value: '' (empty string)

  A password. Used to provide a seed for the password hashing algorithm . Set this to a random string -- longer is better. django-admin.py startproject will automatically create one for you.

(40)SEND_BROKEN_LINK_EMAILS Default: False

  Whether to send an email to MANAGERS when someone from a valid Django-powered page to another Django-powered page finds a 404 error (ie, a dead link is found). This option is valid if and only if CommonMiddleware is installed (See the `middleware documentation`_). See IGNORABLE_404_STARTS `` and IGNORABLE_404_ENDS ``.

(41)SERVER_EMAIL Default value: 'root@localhost'

  The email address used to send error messages, such as to ADMINS and MANAGERS.

(42)SESSION_COOKIE_AGE Default: 1209600 (2 weeks, in seconds)

  Lifetime of session cookies, in seconds. See session docs.

(43)SESSION_COOKIE_DOMAIN Default value: None

  The domain for which session cookies are valid. Set the value to something like ".lawrence.com" for cookies to work across domains, or use None for a standard domain cookie. See session docs.

(44)SESSION_COOKIE_NAME Default value: 'sessionid'

  The cookie name used by the session. See session docs.

(45)SESSION_SAVE_EVERY_REQUEST Default value: False

  Whether to save the session per request. See session docs.

(46)SITE_ID Default value: Not defined

  is an integer representing the current site in the django_site table. When a data contains multiple site data, your program can access the data for a specific site by this ID.

TEMPLATE_CONTEXT_PROCESSORS default value:

("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n")

  A tuple of callables that are used to populate the context in RequestContext. These callables take a request object as their argument and return a dictionary of items to be merged into the context.

(47)TEMPLATE_DEBUG Default value: False

  A boolean value that toggles template debugging mode. If set to True, if there is any TemplateSyntaxError, a detailed error report information page will be displayed to you. This report includes the relevant template snippet, and the corresponding line is automatically highlighted. Note that Django only displays this info page when DEBUG is True. See DEBUG.

(48) TEMPLATE_DIRS Default: () (empty tuple)

  A list of template source file directories, in search order. Note the use of a Unix-style leading slash (ie '/'), even on Windows. See template documentation.

(49)TEMPLATE_LOADERS  默认值: ('django.template.loaders.filesystem.load_template_source',)

  A tuple whose elements are callable objects (in the form of strings). These objects know how to import templates from various sources. See the template documentation.

(50)TEMPLATE_STRING_IF_INVALID Default: '' (empty string)

  Output text, as a string. The template system will use this variable in case of errors (such as misspellings). See How invalid variables are handled.

(51)TIME_FORMAT Default: 'P' (eg 4 pm)

  The default time format used by the Django admin change-list. It is possible that other parts of the system also use this format. See allowed date format strings. See DATE_FORMAT and DATETIME_FORMAT.

(52)TIME_ZONE Default: 'America/Chicago' (we can use 'Asia/Shanghai PRC' )

  A string representing the current time zone. See list of options.

  Django converts all date/times according to this setting --  regardless of the server's time zone setting . For example, a server could serve multiple Django-powered sites, each using a separate time zone setting.

(53)USE_ETAGS Default value: False

  A boolean. Specifies whether to output the "Etag" header. This option saves network bandwidth at the cost of performance. This option is only useful if CommonMiddleware is installed (see middleware documentation)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326071693&siteId=291194637