settings.py 8.1 KB

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