settings.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. """
  2. Django settings for TestLaboratory project.
  3. Generated by 'django-admin startproject' using Django 3.2.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/3.2/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/3.2/ref/settings/
  8. """
  9. import datetime
  10. from pathlib import Path
  11. import sys
  12. import os
  13. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  14. # import apps.user.middleware.authentication
  15. BASE_DIR = Path(__file__).resolve().parent.parent
  16. sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
  17. MEDIA_ROOT = os.path.join(BASE_DIR, 'static')
  18. MEDIA_URL = '/media/'
  19. SOFTWARE_ROOT = "static/software/"
  20. PLAN_ROOT = "static/plan-statement/"
  21. TASK_ROOT = 'static/task-statement/'
  22. CASE_TEMPLATE_ROOT = 'static/case-template/测试用例模版.xlsx'
  23. CASE_FILE_ROOT = 'static/case-file/'
  24. CASE_FILE_EXPORT = 'static/case-file-export/'
  25. USER_FILE_ROOT = 'static/user-file-export/'
  26. HTTP_HEAD = 'http://172.26.0.14:8003/'
  27. # Quick-start development settings - unsuitable for production
  28. # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
  29. # SECURITY WARNING: keep the secret key used in production secret!
  30. SECRET_KEY = 'django-insecure-zo64fvv02msf-se7!dek5*w$17#3nh6zta#!i=79bt9d#f88@i'
  31. # SECURITY WARNING: don't run with debug turned on in production!
  32. DEBUG = True
  33. ALLOWED_HOSTS = ['*']
  34. # AUTH_USER_MODEL = "user.User"
  35. # AUTHENTICATION_BACKENDS = (
  36. # 'user.middleware.authentication.CustomBackend',
  37. # )
  38. # Application definition
  39. INSTALLED_APPS = [
  40. 'simpleui',
  41. 'django.contrib.admin',
  42. 'django.contrib.auth',
  43. 'django.contrib.contenttypes',
  44. 'django.contrib.sessions',
  45. 'django.contrib.messages',
  46. 'django.contrib.staticfiles',
  47. 'rest_framework',
  48. 'corsheaders',
  49. 'user',
  50. 'software',
  51. 'plan',
  52. 'apps.task',
  53. 'file',
  54. 'log',
  55. 'group',
  56. 'company'
  57. ]
  58. MIDDLEWARE = [
  59. 'django.middleware.security.SecurityMiddleware',
  60. 'django.contrib.sessions.middleware.SessionMiddleware',
  61. 'django.middleware.common.CommonMiddleware',
  62. # 'django.middleware.csrf.CsrfViewMiddleware',
  63. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  64. 'django.contrib.messages.middleware.MessageMiddleware',
  65. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  66. 'corsheaders.middleware.CorsMiddleware',
  67. 'django.middleware.common.CommonMiddleware',
  68. ]
  69. ROOT_URLCONF = 'TestLaboratory.urls'
  70. TEMPLATES = [
  71. {
  72. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  73. 'DIRS': [os.path.join(BASE_DIR, 'templates')],
  74. 'APP_DIRS': True,
  75. 'OPTIONS': {
  76. 'context_processors': [
  77. 'django.template.context_processors.debug',
  78. 'django.template.context_processors.request',
  79. 'django.contrib.auth.context_processors.auth',
  80. 'django.contrib.messages.context_processors.messages',
  81. ],
  82. },
  83. },
  84. ]
  85. WSGI_APPLICATION = 'TestLaboratory.wsgi.application'
  86. # Database
  87. # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
  88. DATABASES = {
  89. 'default': {
  90. 'ENGINE': 'django.db.backends.mysql',
  91. 'OPTIONS': {
  92. 'read_default_file': 'Config/database_mysql.cnf',
  93. },
  94. }
  95. }
  96. # Password validation
  97. # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
  98. AUTH_PASSWORD_VALIDATORS = [
  99. {
  100. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  101. },
  102. {
  103. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  104. },
  105. {
  106. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  107. },
  108. {
  109. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  110. },
  111. ]
  112. REST_FRAMEWORK = {
  113. 'DEFAULT_PERMISSION_CLASSES': (
  114. 'rest_framework.permissions.IsAuthenticated'
  115. ),
  116. 'DEFAULT_AUTHENTICATION_CLASSES': (
  117. 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
  118. 'rest_framework.authentication.BasicAuthentication',
  119. 'rest_framework.authentication.SessionAuthentication'
  120. )
  121. }
  122. JWT_AUTH = {
  123. # 设置token有效时间
  124. 'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=60 * 60 * 2)
  125. }
  126. # Internationalization
  127. # https://docs.djangoproject.com/en/3.2/topics/i18n/
  128. LANGUAGE_CODE = 'en-us'
  129. TIME_ZONE = 'Asia/Shanghai'
  130. USE_I18N = True
  131. USE_L10N = True
  132. USE_TZ = False
  133. # Static files (CSS, JavaScript, Images)
  134. # https://docs.djangoproject.com/en/3.2/howto/static-files/
  135. STATIC_URL = '/static/'
  136. STATICFILES_DIRS = [
  137. os.path.join(BASE_DIR, "static"),
  138. ]
  139. # Default primary key field type
  140. # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
  141. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  142. REST_FRAMEWORK = {
  143. "DEFAULT_AUTHENTICATION_CLASSES": ["apps.user.middleware.authentication.JwtAutentication"]
  144. }
  145. CORS_ALLOW_CREDENTIALS = True
  146. CORS_ORIGIN_ALLOW_ALL = True
  147. CORS_ALLOW_METHODS = (
  148. 'GET',
  149. 'POST',
  150. 'PUT',
  151. 'PATCH',
  152. 'DELETE',
  153. 'OPTIONS'
  154. )
  155. CORS_ALLOW_HEADERS = (
  156. 'x-requested-with',
  157. 'content-type',
  158. 'accept',
  159. 'origin',
  160. 'authorization',
  161. 'x-csrftoken'
  162. )
  163. import time
  164. cur_path = os.path.dirname(os.path.realpath(__file__)) # log_path是存放日志的路径
  165. log_path = os.path.join(os.path.dirname(cur_path), 'logs')
  166. if not os.path.exists(log_path): os.mkdir(log_path) # 如果不存在这个logs文件夹,就自动创建一个
  167. LOGGING = {
  168. 'version': 1,
  169. 'disable_existing_loggers': False,
  170. 'formatters': {
  171. # 日志格式
  172. 'standard': {
  173. 'format': '[%(levelname)s] [%(asctime)s] [%(filename)s:%('
  174. 'lineno)d] [%(module)s:%(funcName)s] '
  175. '- %(message)s'},
  176. 'simple': { # 简单格式
  177. 'format': '%(levelname)s %(message)s'
  178. },
  179. },
  180. # 过滤
  181. 'filters': {
  182. 'require_debug_true': {
  183. '()': 'django.utils.log.RequireDebugTrue', # 过滤掉调试信息
  184. },
  185. },
  186. # 定义具体处理日志的方式
  187. 'handlers': {
  188. # 默认记录所有日志
  189. 'default': {
  190. 'level': 'INFO',
  191. 'class': 'logging.handlers.RotatingFileHandler',
  192. 'filename': os.path.join(log_path, 'all-{}.log'.format(
  193. time.strftime('%Y-%m-%d'))),
  194. 'maxBytes': 1024 * 1024 * 300, # 文件大小
  195. 'backupCount': 10, # 备份数
  196. 'formatter': 'standard', # 输出格式
  197. 'encoding': 'utf-8', # 设置默认编码,否则打印出来汉字乱码
  198. },
  199. # 输出错误日志
  200. 'error': {
  201. 'level': 'ERROR',
  202. 'class': 'logging.handlers.RotatingFileHandler',
  203. 'filename': os.path.join(log_path, 'error-{}.log'.format(
  204. time.strftime('%Y-%m-%d'))),
  205. 'maxBytes': 1024 * 1024 * 5, # 文件大小
  206. 'backupCount': 5, # 备份数
  207. 'formatter': 'standard', # 输出格式
  208. 'encoding': 'utf-8', # 设置默认编码
  209. },
  210. # 控制台输出
  211. 'console': {
  212. 'level': 'DEBUG',
  213. 'class': 'logging.StreamHandler',
  214. 'formatter': 'standard'
  215. },
  216. #输出info日志
  217. 'info': {
  218. 'level': 'INFO',
  219. 'class': 'logging.handlers.RotatingFileHandler',
  220. 'filename': os.path.join(log_path, 'info-{}.log'.format(
  221. time.strftime('%Y-%m-%d'))),
  222. 'maxBytes': 1024 * 1024 * 5,
  223. 'backupCount': 5,
  224. 'formatter': 'standard',
  225. 'encoding': 'utf-8', # 设置默认编码
  226. },
  227. },
  228. # 配置用哪几种 handlers 来处理日志
  229. 'loggers': {
  230. # 类型 为 django 处理所有类型的日志, 默认调用
  231. 'django': {
  232. 'handlers': ['default', 'console'],
  233. 'level': 'INFO',
  234. 'propagate': False
  235. },
  236. # log 调用时需要当作参数传入
  237. 'log': {
  238. 'handlers': ['error', 'info', 'console', 'default'],
  239. 'level': 'INFO',
  240. 'propagate': True
  241. },
  242. }
  243. }
  244. """
  245. python manage.py runserver 172.16.100.180:8000
  246. """