settings.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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'
  68. SERVER_HOST = 'database-2.clraczw4p0yj.us-west-1.rds.amazonaws.com'
  69. DATABASES_USER = 'azrds'
  70. DATABASES_PASS = 'azrds.x.x'
  71. DATABASES = {'default': {
  72. 'ENGINE': 'django.db.backends.mysql',
  73. 'NAME': DATABASE_DATA,
  74. 'USER': DATABASES_USER,
  75. 'PASSWORD': DATABASES_PASS,
  76. 'HOST': SERVER_HOST,
  77. 'PORT': '3306',
  78. 'OPTIONS': {'charset': 'utf8mb4', 'use_unicode': True, 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},
  79. 'AUTOCOMMIT': True
  80. }}
  81. # Password validation
  82. # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
  83. AUTH_PASSWORD_VALIDATORS = [
  84. {
  85. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  86. },
  87. {
  88. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  89. },
  90. {
  91. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  92. },
  93. {
  94. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  95. },
  96. ]
  97. # Internationalization
  98. # https://docs.djangoproject.com/en/2.1/topics/i18n/
  99. LANGUAGE_CODE = 'en-us'
  100. TIME_ZONE = 'UTC'
  101. USE_I18N = True
  102. USE_L10N = True
  103. USE_TZ = True
  104. # Static files (CSS, JavaScript, Images)
  105. # https://docs.djangoproject.com/en/2.1/howto/static-files/
  106. STATIC_URL = '/static/'
  107. # 跨域增加忽略
  108. CORS_ALLOW_CREDENTIALS = True
  109. CORS_ORIGIN_ALLOW_ALL = True
  110. CORS_ORIGIN_WHITELIST = ()
  111. CORS_ALLOW_METHODS = (
  112. 'DELETE',
  113. 'GET',
  114. 'OPTIONS',
  115. 'PATCH',
  116. 'POST',
  117. 'PUT',
  118. 'VIEW',
  119. )
  120. CORS_ALLOW_HEADERS = (
  121. 'accept',
  122. 'accept-encoding',
  123. 'authorization',
  124. 'content-type',
  125. 'dnt',
  126. 'origin',
  127. 'user-agent',
  128. 'x-csrftoken',
  129. 'x-requested-with',
  130. )
  131. LOGGING = {
  132. 'version': 1,
  133. 'disable_existing_loggers': False if DEBUG else True, # 是否禁用已经存在的日志器
  134. 'formatters': { # 日志信息显示的格式
  135. 'verbose': {
  136. 'format': '%(levelname)s %(asctime)s %(module)s %(lineno)s %(message)s'
  137. # "class": "pythonjsonlogger.jsonlogger.JsonFormatter"
  138. },
  139. 'simple': {
  140. 'format': '%(levelname)s %(asctime)s %(module)s %(funcName)s %(lineno)d %(message)s'
  141. # "class": "pythonjsonlogger.jsonlogger.JsonFormatter"
  142. }, # 日志记录级别+时间日期+模块名称+函数名称+行号+记录消息
  143. },
  144. 'filters': { # 对日志进行过滤
  145. 'require_debug_true': { # django在debug模式下才输出日志
  146. '()': 'django.utils.log.RequireDebugTrue',
  147. },
  148. },
  149. 'handlers': { # 日志处理方法
  150. 'console': { # 向终端中输出日志
  151. 'level': 'DEBUG' if DEBUG else 'INFO',
  152. 'filters': ['require_debug_true'], # debug为true才会输出
  153. 'class': 'logging.StreamHandler',
  154. 'formatter': 'verbose'
  155. },
  156. 'info': { # 向文件中输出日志
  157. 'level': 'INFO',
  158. 'class': 'logging.handlers.RotatingFileHandler',
  159. 'filename': os.path.join(BASE_DIR + '/logs/', "info.log"), # 日志文件的位置
  160. 'maxBytes': 300 * 1024 * 1024, # 300M大小
  161. 'backupCount': 10,
  162. 'formatter': 'verbose',
  163. 'encoding': 'utf-8'
  164. },
  165. },
  166. 'loggers': { # 日志器
  167. "django": { # 默认的logger应用如下配置
  168. "handlers": ["info", "console"],
  169. "propagate": True,
  170. "level": "INFO"
  171. },
  172. }
  173. }