settings.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. """
  2. Django settings for AnsjerUIDManage project.
  3. Generated by 'django-admin startproject' using Django 3.0.7.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/3.0/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/3.0/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/3.0/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = 'k#i*q_^=nhr^63ytqenfg!ecqizq60*6_x@sp_6+%u^b24%+fj'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = False
  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. 'Model.apps.ModelConfig',
  28. 'corsheaders',
  29. ]
  30. MIDDLEWARE = [
  31. 'django.middleware.security.SecurityMiddleware',
  32. 'Service.LogMiddleware.LogMiddleware',
  33. 'django.contrib.sessions.middleware.SessionMiddleware',
  34. 'django.middleware.common.CommonMiddleware',
  35. #'django.middleware.csrf.CsrfViewMiddleware',
  36. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  37. 'django.contrib.messages.middleware.MessageMiddleware',
  38. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  39. 'corsheaders.middleware.CorsMiddleware',
  40. 'corsheaders.middleware.CorsPostCsrfMiddleware',
  41. ]
  42. ROOT_URLCONF = 'AnsjerUIDManage.urls'
  43. CORS_ALLOW_CREDENTIALS = True
  44. CORS_ORIGIN_ALLOW_ALL = True
  45. CORS_ALLOW_METHODS = (
  46. 'DELETE',
  47. 'GET',
  48. 'OPTIONS',
  49. 'PATCH',
  50. 'POST',
  51. 'PUT',
  52. 'VIEW',
  53. )
  54. CORS_ALLOW_HEADERS = (
  55. 'XMLHttpRequest',
  56. 'X_FILENAME',
  57. 'accept',
  58. 'accept-encoding',
  59. 'authorization',
  60. 'content-type',
  61. 'dnt',
  62. 'origin',
  63. 'user-agent',
  64. 'x-csrftoken',
  65. 'x-requested-with',
  66. 'Pragma',
  67. )
  68. TEMPLATES = [
  69. {
  70. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  71. 'DIRS': [os.path.join(BASE_DIR, 'templates')]
  72. ,
  73. 'APP_DIRS': True,
  74. 'OPTIONS': {
  75. 'context_processors': [
  76. 'django.template.context_processors.debug',
  77. 'django.template.context_processors.request',
  78. 'django.contrib.auth.context_processors.auth',
  79. 'django.contrib.messages.context_processors.messages',
  80. ],
  81. },
  82. },
  83. ]
  84. WSGI_APPLICATION = 'AnsjerUIDManage.wsgi.application'
  85. # Database
  86. # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
  87. DATABASES = {
  88. # 'default': {
  89. # 'ENGINE': 'django.db.backends.sqlite3',
  90. # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  91. # 'CHECK_SAME_THREAD': False
  92. # }
  93. 'default': {
  94. 'ENGINE': 'django.db.backends.mysql',
  95. 'NAME': 'ansjer_uid',
  96. 'USER': 'root',
  97. 'PASSWORD': 'ansjer.x.x',
  98. 'HOST': 'localhost',
  99. 'PORT': '3306',
  100. 'OPTIONS': {'charset': 'utf8mb4', 'use_unicode': True, 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},
  101. 'AUTOCOMMIT': True
  102. }
  103. }
  104. # Password validation
  105. # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
  106. AUTH_PASSWORD_VALIDATORS = [
  107. {
  108. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  109. },
  110. {
  111. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  112. },
  113. {
  114. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  115. },
  116. {
  117. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  118. },
  119. ]
  120. # Internationalization
  121. # https://docs.djangoproject.com/en/3.0/topics/i18n/
  122. LANGUAGE_CODE = 'en-us'
  123. TIME_ZONE = 'UTC'
  124. USE_I18N = True
  125. USE_L10N = True
  126. USE_TZ = True
  127. # Static files (CSS, JavaScript, Images)
  128. # https://docs.djangoproject.com/en/3.0/howto/static-files/
  129. STATIC_URL = '/static/'
  130. # 日志模块
  131. LOGGING = {
  132. 'version': 1,
  133. 'disable_existing_loggers': True,
  134. 'formatters': {
  135. 'error_format': {
  136. # 'format': '{"asctime":"%(asctime)s","thread":"%(threadName)s:%(thread)d","errorline":"%(lineno)d","errorlevel":"%(levelname)s","errorcontent":"%(message)s"}'
  137. 'format': '%(asctime)s %(threadName)s %(thread)d %(lineno)d %(levelname)s %(message)s'
  138. },
  139. },
  140. 'filters': {
  141. },
  142. 'handlers': {
  143. 'mail_admins': {
  144. 'level': 'ERROR',
  145. 'class': 'django.utils.log.AdminEmailHandler',
  146. 'include_html': True,
  147. },
  148. 'default': {
  149. 'level': 'ERROR',
  150. 'class': 'logging.handlers.RotatingFileHandler',
  151. 'filename': BASE_DIR + '/static/log/error.log',
  152. 'maxBytes': 1024 * 1024 * 5, # 5 MB
  153. 'backupCount': 5,
  154. 'formatter': 'error_format',
  155. },
  156. 'console': {
  157. 'level': 'ERROR',
  158. 'class': 'logging.StreamHandler',
  159. 'formatter': 'error_format'
  160. },
  161. },
  162. 'loggers': {
  163. 'django': {
  164. 'handlers': ['default', 'console'],
  165. # 'handlers': ['mail_admins','default','console'],
  166. 'level': 'ERROR',
  167. 'propagate': False
  168. },
  169. }
  170. }