settings.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. """
  2. Django settings for azoauth project.
  3. Generated by 'django-admin startproject' using Django 2.1.4.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/2.1/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/2.1/ref/settings/
  8. """
  9. import os
  10. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  11. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  12. # Quick-start development settings - unsuitable for production
  13. # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = 'p7!s!=fn!a^e_&r46)*8*4y-bdyam$m@kr31e!+r56dtv##bz1'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = True
  18. ALLOWED_HOSTS = ['*']
  19. # Application definition
  20. INSTALLED_APPS = [
  21. 'django.contrib.admin',
  22. 'django.contrib.auth',
  23. 'django.contrib.contenttypes',
  24. 'django.contrib.sessions',
  25. 'django.contrib.messages',
  26. 'django.contrib.staticfiles',
  27. 'corsheaders',
  28. 'model'
  29. ]
  30. MIDDLEWARE = [
  31. 'django.middleware.security.SecurityMiddleware',
  32. 'django.contrib.sessions.middleware.SessionMiddleware',
  33. 'django.middleware.common.CommonMiddleware',
  34. # 'django.middleware.csrf.CsrfViewMiddleware',
  35. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  36. 'django.contrib.messages.middleware.MessageMiddleware',
  37. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  38. 'corsheaders.middleware.CorsMiddleware',
  39. 'django.middleware.common.CommonMiddleware',
  40. ]
  41. ROOT_URLCONF = 'azoauth.urls'
  42. TEMPLATES = [
  43. {
  44. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  45. 'DIRS': [os.path.join(BASE_DIR, 'templates')]
  46. ,
  47. 'APP_DIRS': True,
  48. 'OPTIONS': {
  49. 'context_processors': [
  50. 'django.template.context_processors.debug',
  51. 'django.template.context_processors.request',
  52. 'django.contrib.auth.context_processors.auth',
  53. 'django.contrib.messages.context_processors.messages',
  54. ],
  55. },
  56. },
  57. ]
  58. WSGI_APPLICATION = 'azoauth.wsgi.application'
  59. # Database
  60. # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
  61. DATABASES = {
  62. 'default': {
  63. 'ENGINE': 'django.db.backends.sqlite3',
  64. 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  65. }
  66. }
  67. # DATABASE_DATA = 'alexa_oauth'
  68. # SERVER_HOST = 'azrdsinstance.clraczw4p0yj.us-west-1.rds.amazonaws.com'
  69. # DATABASES_USER = 'azrds'
  70. # DATABASES_PASS = 'azrds.x.x'
  71. #
  72. # DATABASES = {'default': {
  73. # 'ENGINE': 'django.db.backends.mysql',
  74. # 'NAME': DATABASE_DATA,
  75. # 'USER': DATABASES_USER,
  76. # 'PASSWORD': DATABASES_PASS,
  77. # 'HOST': SERVER_HOST,
  78. # 'PORT': '3306',
  79. # 'OPTIONS': {'charset': 'utf8mb4', 'use_unicode': True, 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},
  80. # 'AUTOCOMMIT': True
  81. # }}
  82. # Password validation
  83. # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
  84. AUTH_PASSWORD_VALIDATORS = [
  85. {
  86. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  87. },
  88. {
  89. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  90. },
  91. {
  92. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  93. },
  94. {
  95. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  96. },
  97. ]
  98. # Internationalization
  99. # https://docs.djangoproject.com/en/2.1/topics/i18n/
  100. LANGUAGE_CODE = 'en-us'
  101. TIME_ZONE = 'UTC'
  102. USE_I18N = True
  103. USE_L10N = True
  104. USE_TZ = True
  105. # Static files (CSS, JavaScript, Images)
  106. # https://docs.djangoproject.com/en/2.1/howto/static-files/
  107. STATIC_URL = '/static/'
  108. # 跨域增加忽略
  109. CORS_ALLOW_CREDENTIALS = True
  110. CORS_ORIGIN_ALLOW_ALL = True
  111. CORS_ORIGIN_WHITELIST = ()
  112. CORS_ALLOW_METHODS = (
  113. 'DELETE',
  114. 'GET',
  115. 'OPTIONS',
  116. 'PATCH',
  117. 'POST',
  118. 'PUT',
  119. 'VIEW',
  120. )
  121. CORS_ALLOW_HEADERS = (
  122. 'accept',
  123. 'accept-encoding',
  124. 'authorization',
  125. 'content-type',
  126. 'dnt',
  127. 'origin',
  128. 'user-agent',
  129. 'x-csrftoken',
  130. 'x-requested-with',
  131. )
  132. LOGGING = {
  133. 'version': 1,
  134. 'disable_existing_loggers': False if DEBUG else True, # 是否禁用已经存在的日志器
  135. 'formatters': { # 日志信息显示的格式
  136. 'verbose': {
  137. 'format': '%(levelname)s %(asctime)s %(module)s %(lineno)s %(message)s'
  138. # "class": "pythonjsonlogger.jsonlogger.JsonFormatter"
  139. },
  140. 'simple': {
  141. 'format': '%(levelname)s %(asctime)s %(module)s %(funcName)s %(lineno)d %(message)s'
  142. # "class": "pythonjsonlogger.jsonlogger.JsonFormatter"
  143. }, # 日志记录级别+时间日期+模块名称+函数名称+行号+记录消息
  144. },
  145. 'filters': { # 对日志进行过滤
  146. 'require_debug_true': { # django在debug模式下才输出日志
  147. '()': 'django.utils.log.RequireDebugTrue',
  148. },
  149. },
  150. 'handlers': { # 日志处理方法
  151. 'console': { # 向终端中输出日志
  152. 'level': 'DEBUG' if DEBUG else 'INFO',
  153. 'filters': ['require_debug_true'], # debug为true才会输出
  154. 'class': 'logging.StreamHandler',
  155. 'formatter': 'verbose'
  156. },
  157. 'info': { # 向文件中输出日志
  158. 'level': 'INFO',
  159. 'class': 'logging.handlers.RotatingFileHandler',
  160. 'filename': os.path.join(BASE_DIR+'/logs/', "info.log"), # 日志文件的位置
  161. 'maxBytes': 300 * 1024 * 1024, # 300M大小
  162. 'backupCount': 10,
  163. 'formatter': 'verbose',
  164. 'encoding': 'utf-8'
  165. },
  166. },
  167. 'loggers': { # 日志器
  168. "django": { # 默认的logger应用如下配置
  169. "handlers": ["info", "console"],
  170. "propagate": True,
  171. "level": "INFO"
  172. },
  173. }
  174. }