djiango 配置文件(setings)

"""
Django settings for ORM project.
 
Generated by 'django-admin startproject' using Django 1.10.5.
 
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
 
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""
 
import os
 
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
 
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
 
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-pasr(osd7j9maaiqp0eibz1_v01&0b5hco+1sr*s1yy#ip)1!'
 
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
 
ALLOWED_HOSTS = []
 
 
# Application definition
 
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'app01',
]
 
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
 
ROOT_URLCONF = 'ORM.urls'
 
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
 
WSGI_APPLICATION = 'ORM.wsgi.application'
 
 
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
 
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
 
 
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
 
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]
 
 
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
 
LANGUAGE_CODE = 'en-us'
 
TIME_ZONE = 'UTC'
 
USE_I18N = True
 
USE_L10N = True
 
USE_TZ = True
 
 
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
 
STATIC_URL = '/static/'
View Code

1. ALLOWED_HOSTS

DEBUG = True

ALLOWED_HOSTS = []

默认为一个空列表,代表此Django网站可以可以提供的主机/域名的字符串列表。当DEUG = True  和  ALLOWED_HOSTS  是空的时候,默认将对本机('localhost')进行验证

2.INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'app01',
]
View Code

django.contrib.admin —— 管理站点。
django.contrib.auth —— 认证系统。
django.contrib.contenttypes —— 用于内容类型的框架。
django.contrib.sessions —— 会话框架。
django.contrib.messages —— 消息框架。
django.contrib.staticfiles —— 管理静态文件的框架。
app01 是创建应用app的名字,如果项目创建了app则必须要添加app的名字

3.MIDDLEWARE_CLASSES

一个django 用到的中间件 class 名称的 tuple. 参阅 middleware 文档.

4.ROOT_URLCONF

默认值: Not defined

一个字符串,表示你的根 URLconf 的模块名. 举例来说:"mydjangoapps.urls".

5.TEMPLATE_DIRS

默认值: () (空的 tuple)

模板源文件目录列表,按搜索顺序. 注意要使用 Unix-风格的前置斜线(即'/')

6.WSGI_APPLICATION

WSGI_APPLICATION 所指定的即为 wsgi.py 中的全局变量 application。在 get_wsgi_application() 中实例化了 WSGIHandler, 并无其他操作.

7.STATIC_ROOT

运行上边提到的命令:python manage.py collectstatic 之后静态文件将要复制到的目录,这个目录只有在运行collectstatic时候才会用到,不能想当然的以为这个目录和MEDIA_ROOT的作用是相同的,否则在开发环境的时候可能一直无法找到静态文件。

8.STATIC_URL

设置的static file的起始url,这个只是在template里边引用到,这个参数和MEDIA_URL的含义相同。

9.STATICFILES_DIRS

和TEMPLATE_DIRS的含义差不多,就是除了各个app的static目录以外还需要管理的静态文件设置,比如项目的公共文件差不多。

10.AUTH_USER_MODEL

自从django 1.5之后, 用户可以自定义User model了, 如果需要外键使用user model

posted @ 2017-06-12 14:39  dba_devops  阅读(1085)  评论(0编辑  收藏  举报