Django框架中settings.py注释
1 # coding:utf8 2 """ 3 Django settings for DjangoTest project. 4 5 Generated by 'django-admin startproject' using Django 1.8. 6 7 For more information on this file, see 8 https://docs.djangoproject.com/en/1.8/topics/settings/ 9 10 For the full list of settings and their values, see 11 https://docs.djangoproject.com/en/1.8/ref/settings/ 12 """ 13 14 # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 15 import os 16 17 # C:\DjangoTest\DjangoTest\settings.py 18 # C:\DjangoTest\DjangoTest\ 19 # 获取项目的根路径 20 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 21 22 23 # Quick-start development settings - unsuitable for production 24 # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ 25 26 # SECURITY WARNING: keep the secret key used in production secret! 27 # 生成用户名的时候,加密字符串 28 SECRET_KEY = 'c04ku^%jij7u!w3ss9536n9t3dt12=e-wmwovyeia_f2+81oir' 29 30 # SECURITY WARNING: don't run with debug turned on in production! 31 # 开启调试模式 32 # 1.视图函数变动,自动重启服务器 33 # 2.错误详细输出,环境变量 34 # 3.生产环境中需要关闭 35 DEBUG = True 36 37 # 允许访问的域名或者IP地址 38 ALLOWED_HOSTS = ['*'] 39 40 41 # Application definition 42 # 新建app需要加到这里 43 INSTALLED_APPS = ( 44 'django.contrib.admin', 45 'django.contrib.auth', 46 'django.contrib.contenttypes', 47 'django.contrib.sessions', 48 'django.contrib.messages', 49 'django.contrib.staticfiles', 50 'app01', 51 'app02', 52 'app03', 53 ) 54 55 # 中间件,响应前自动处理 56 MIDDLEWARE_CLASSES = ( 57 'django.contrib.sessions.middleware.SessionMiddleware', 58 'django.middleware.common.CommonMiddleware', 59 # 'django.middleware.csrf.CsrfViewMiddleware', 60 'django.contrib.auth.middleware.AuthenticationMiddleware', 61 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 62 'django.contrib.messages.middleware.MessageMiddleware', 63 'django.middleware.clickjacking.XFrameOptionsMiddleware', 64 'django.middleware.security.SecurityMiddleware', 65 ) 66 67 # 指项目文件下同名文件夹下的urls,项目改名字这里也要改 68 ROOT_URLCONF = 'DjangoTest.urls' 69 70 # 指定模板路径 BASE_DIR是项目根路径,有别的模板也要加进来 71 TEMPLATES = [ 72 { 73 'BACKEND': 'django.template.backends.django.DjangoTemplates', 74 # 'DIRS': [BASE_DIR / 'templates'] 原语句报错TypeError: unsupported operand type(s) for /: 'str' and 'str' 75 # 'DIRS': [BASE_DIR, 'templates'] 76 'DIRS': [str.format(BASE_DIR, '/templates')] 77 , # 指定模板路径 BASE_DIR是项目根路径,有别的模板也要加进来 78 'APP_DIRS': True, # 开启会去app下找模板文件 79 'OPTIONS': { 80 'context_processors': [ 81 'django.template.context_processors.debug', 82 'django.template.context_processors.request', 83 'django.contrib.auth.context_processors.auth', 84 'django.contrib.messages.context_processors.messages', 85 ], 86 }, 87 }, 88 ] 89 90 WSGI_APPLICATION = 'DjangoTest.wsgi.application' 91 92 93 # Database 94 # https://docs.djangoproject.com/en/1.8/ref/settings/#databases 95 # 数据库连接配置,默认连接根目录下sqlite3 96 DATABASES = { 97 # 'default': { 98 # 'ENGINE': 'django.db.backends.sqlite3', 99 # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 100 'default': { 101 'ENGINE': 'django.db.backends.mysql', # 数据库引擎 102 'NAME': '*', # 数据库名 103 'HOST': '127.0.0.1', 104 'USER': 'root', # MySQL数据库用户名 105 'PASSWORD': '*', 106 'PORT': 3306, 107 } 108 } 109 110 111 # Password validation 112 # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 113 114 115 # Internationalization 116 # https://docs.djangoproject.com/en/1.8/topics/i18n/ 117 118 # 后台admin的语言 119 # LANGUAGE_CODE = 'en-us' 120 LANGUAGE_CODE = 'zh-hans' 121 122 TIME_ZONE = 'UTC' 123 124 USE_I18N = True 125 126 USE_L10N = True 127 128 USE_TZ = False 129 130 131 # Static files (CSS, JavaScript, Images) 132 # https://docs.djangoproject.com/en/1.8/howto/static-files/ 133 134 # 静态文件的路由(url)地址 135 STATIC_URL = '/static/' 136 137 # 静态文件路径地址 138 STATICFILES_DIRS = ( 139 os.path.join(BASE_DIR, 'static'), 140 ) 141 142 # django日志配置 143 LOGGING = { 144 'version': 1, 145 'disable_existing_loggers': True, 146 147 'formatters': { # 日志格式 148 'standard': { 149 'format': '%(asctime)s [%(name)s:%(lineno)d] [%(module)s:%(funcName)s] [%(levelname)s]- %(message)s'} 150 }, 151 # 日志处理器 152 'handlers': { # 默认记录所有日志 153 'file': { # 基于文件的处理器 154 'level': 'DEBUG', 155 'class': 'logging.FileHandler', 156 'filename': 'log/debug.log', 157 'formatter': 'standard', # 输出格式 158 }, 159 'console': { # 基于控制台日志 160 'level': 'DEBUG', 161 'class': 'logging.StreamHandler', 162 'formatter': 'standard' 163 }, 164 }, 165 # 日志器 166 'loggers': { 167 # 日志器名称;日志器字典 168 'app04': { 169 'handlers': ['file', 'console'], # 可以设置多个handlers 170 'level': 'DEBUG', 171 'propagate': False 172 }, 173 # log 调用时需要当作参数传入 174 'stu.views': { 175 'handlers': ['console'], 176 'level': 'ERROR', 177 'propagate': False 178 # propagate如果设置为True默认会向上一个级别找相应logger来继续处理,一般我们会设置为False不向上找 179 }, 180 } 181 }