settings.py 8.0 KB

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