settings.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import os
  2. #SERVER_TYPE = 'test'
  3. SERVER_TYPE = 'formal'
  4. SECRET_KEY = 'c7ki2_gkg4#sjfm-u1%$s#&n#szf01f*v69rwv2qsf#-zmm@tl'
  5. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  6. DEBUG = True
  7. # DEBUG = False
  8. ALLOWED_HOSTS = ['*']
  9. INSTALLED_APPS = [
  10. 'django.contrib.admin',
  11. 'django.contrib.auth',
  12. 'django.contrib.contenttypes',
  13. 'django.contrib.sessions',
  14. 'django.contrib.messages',
  15. 'django.contrib.staticfiles',
  16. 'corsheaders',
  17. 'imagekit',
  18. 'Model',
  19. ]
  20. MIDDLEWARE = [
  21. 'corsheaders.middleware.CorsMiddleware',
  22. 'Service.middleware.StatisticsUrlMiddleware',
  23. 'django.middleware.security.SecurityMiddleware',
  24. 'django.contrib.sessions.middleware.SessionMiddleware',
  25. 'django.middleware.common.CommonMiddleware',
  26. # 'django.middleware.csrf.CsrfViewMiddleware',
  27. 'corsheaders.middleware.CorsPostCsrfMiddleware',
  28. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  29. 'django.contrib.messages.middleware.MessageMiddleware',
  30. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  31. 'django.middleware.security.SecurityMiddleware',
  32. 'django_global_request.middleware.GlobalRequestMiddleware',
  33. ]
  34. AUTHENTICATION_BACKENDS = (
  35. 'django.contrib.auth.backends.ModelBackend', # django default backend
  36. 'guardian.backends.ObjectPermissionBackend',
  37. )
  38. ADDR_URL = []
  39. ANONYMOUS_USER_ID = -1 # 支持匿名用户
  40. STATIC_URL = '/static/'
  41. # 上传路径根目录
  42. MEDIA_ROOT = os.path.join(BASE_DIR, 'static/Upgrate')
  43. # 在浏览器上访问该上传文件的url的前缀
  44. MEDIA_URL = '/static/Upgrate/'
  45. ROOT_URLCONF = 'Ansjer.urls'
  46. LOGIN_URL = '/account/login'
  47. AUTH_USER_MODEL = 'Model.Device_User' # 自定义Model
  48. APPEND_SLASH = False
  49. TEMPLATES = [
  50. {
  51. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  52. 'DIRS': [BASE_DIR + '/static/templates', ],
  53. 'APP_DIRS': True,
  54. 'OPTIONS': {
  55. 'context_processors': [
  56. 'django.template.context_processors.debug',
  57. 'django.template.context_processors.request',
  58. 'django.contrib.auth.context_processors.auth',
  59. 'django.contrib.messages.context_processors.messages',
  60. ],
  61. },
  62. },
  63. ]
  64. WSGI_APPLICATION = 'Ansjer.wsgi.application'
  65. # 服务器类型
  66. if SERVER_TYPE == 'local':
  67. DATABASE_DATA = 'Ansjer'
  68. SERVER_HOST = '192.168.136.45'
  69. elif SERVER_TYPE == 'test':
  70. NGINX_RTMP_STAT = 'http://13.56.215.252:82/stat'
  71. DATABASE_DATA = 'AnsjerTest'
  72. SERVER_HOST = 'localhost'
  73. elif SERVER_TYPE == 'formal':
  74. DATABASE_DATA = 'Ansjer81'
  75. SERVER_HOST = 'localhost'
  76. DATABASES = {'default': {
  77. 'ENGINE': 'django.db.backends.mysql',
  78. 'NAME': DATABASE_DATA,
  79. 'USER': 'ansjer',
  80. 'PASSWORD': '1234',
  81. 'HOST': SERVER_HOST,
  82. 'PORT': '3306',
  83. 'OPTIONS': {'charset': 'utf8mb4', 'use_unicode': True, 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},
  84. 'AUTOCOMMIT': True
  85. }}
  86. AUTH_PASSWORD_VALIDATORS = [
  87. {
  88. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  89. },
  90. {
  91. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  92. },
  93. {
  94. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  95. },
  96. {
  97. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  98. },
  99. ]
  100. LANGUAGE_CODE = 'en-us'
  101. TIME_ZONE = 'Asia/Shanghai'
  102. # TIME_ZONE = 'UTC'
  103. USE_I18N = True
  104. USE_L10N = True
  105. USE_TZ = True
  106. # 跨域增加忽略
  107. CORS_ALLOW_CREDENTIALS = True
  108. CORS_ORIGIN_ALLOW_ALL = True
  109. CORS_ORIGIN_WHITELIST = ('*')
  110. CORS_ALLOW_METHODS = (
  111. 'DELETE',
  112. 'GET',
  113. 'OPTIONS',
  114. 'PATCH',
  115. 'POST',
  116. 'PUT',
  117. 'VIEW',
  118. )
  119. CORS_ALLOW_HEADERS = (
  120. 'XMLHttpRequest',
  121. 'X_FILENAME',
  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. 'Pragma',
  132. )
  133. #########################################
  134. '''
  135. 增加错误信息推送到管理员邮箱
  136. '''
  137. # 管理员邮箱
  138. ADMINS = (
  139. ('admin', 'chanjunkai@163.com'),
  140. ('admin', '1379072853@qq.com'),
  141. )
  142. # 非空链接,却发生404错误,发送通知MANAGERS
  143. SEND_BROKEN_LINK_EMAILS = True
  144. MANAGERS = ADMINS
  145. # Email设置
  146. EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  147. EMAIL_HOST = 'smtp.163.com' # QQ邮箱SMTP服务器(邮箱需要开通SMTP服务)
  148. EMAIL_PORT = 25 # QQ邮箱SMTP服务端口
  149. EMAIL_HOST_USER = 'chanjunkai@163.com' # 我的邮箱帐号
  150. EMAIL_HOST_PASSWORD = 'cjk1234' # 授权码
  151. EMAIL_SUBJECT_PREFIX = 'website' # 为邮件标题的前缀,默认是'[django]'
  152. EMAIL_USE_TLS = True # 开启安全链接
  153. DEFAULT_FROM_EMAIL = SERVER_EMAIL = EMAIL_HOST_USER # 设置发件人
  154. LOGGING = {
  155. 'version': 1,
  156. 'disable_existing_loggers': True,
  157. 'formatters': {
  158. 'error_format': {
  159. # 'format': '{"asctime":"%(asctime)s","thread":"%(threadName)s:%(thread)d","errorline":"%(lineno)d","errorlevel":"%(levelname)s","errorcontent":"%(message)s"}'
  160. 'format': '%(asctime)s %(threadName)s %(thread)d %(lineno)d %(levelname)s %(message)s'
  161. },
  162. },
  163. 'filters': {
  164. },
  165. 'handlers': {
  166. 'mail_admins': {
  167. 'level': 'ERROR',
  168. 'class': 'django.utils.log.AdminEmailHandler',
  169. 'include_html': True,
  170. },
  171. 'default': {
  172. 'level': 'ERROR',
  173. 'class': 'logging.handlers.RotatingFileHandler',
  174. 'filename': BASE_DIR + '/static/log/error.log',
  175. 'maxBytes': 1024 * 1024 * 5, # 5 MB
  176. 'backupCount': 5,
  177. 'formatter': 'error_format',
  178. },
  179. 'console': {
  180. 'level': 'ERROR',
  181. 'class': 'logging.StreamHandler',
  182. 'formatter': 'error_format'
  183. },
  184. },
  185. 'loggers': {
  186. 'django': {
  187. 'handlers': ['default', 'console'],
  188. # 'handlers': ['mail_admins','default','console'],
  189. 'level': 'ERROR',
  190. 'propagate': False
  191. },
  192. }
  193. }