settings.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. """
  2. Django settings for ks project.
  3. Generated by 'django-admin startproject' using Django 2.2.5.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/2.2/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/2.2/ref/settings/
  8. """
  9. import os, datetime
  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/2.2/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = '-u0fk$orr=_6ac0$l8)4$n(k3-=p2)(pc(gt4wqt1js2u+ouo2'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = True
  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. 'corsheaders',
  28. 'rest_framework',
  29. 'rest_framework_jwt',
  30. 'django_filters',
  31. 'apps.system',
  32. 'apps.foundation',
  33. 'apps.staff',
  34. 'apps.knowledge',
  35. 'apps.examination.exam',
  36. 'apps.examination.exampaper',
  37. 'apps.examination.examquestion',
  38. 'apps.practise.errorbook',
  39. 'apps.practise.practiselog',
  40. ]
  41. MIDDLEWARE = [
  42. 'django.middleware.security.SecurityMiddleware',
  43. 'django.contrib.sessions.middleware.SessionMiddleware',
  44. 'django.middleware.common.CommonMiddleware',
  45. 'django.middleware.csrf.CsrfViewMiddleware',
  46. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  47. 'django.contrib.messages.middleware.MessageMiddleware',
  48. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  49. 'corsheaders.middleware.CorsMiddleware',
  50. ]
  51. CORS_ALLOW_CREDENTIALS = True
  52. CORS_ORIGIN_ALLOW_ALL = True
  53. CORS_ALLOW_METHODS = (
  54. 'DELETE',
  55. 'GET',
  56. 'OPTIONS',
  57. 'PATCH',
  58. 'POST',
  59. 'PUT',
  60. 'VIEW',
  61. )
  62. CORS_ALLOW_HEADERS = (
  63. 'XMLHttpRequest',
  64. 'X_FILENAME',
  65. 'accept-encoding',
  66. 'authorization',
  67. 'content-type',
  68. 'dnt',
  69. 'origin',
  70. 'token',
  71. 'user-agent',
  72. 'x-csrftoken',
  73. 'x-requested-with',
  74. 'Pragma',
  75. )
  76. ROOT_URLCONF = 'ks.urls'
  77. AUTH_USER_MODEL = "staff.User"
  78. AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.AllowAllUsersModelBackend']
  79. TEMPLATES = [
  80. {
  81. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  82. 'DIRS': [],
  83. 'APP_DIRS': True,
  84. 'OPTIONS': {
  85. 'context_processors': [
  86. 'django.template.context_processors.debug',
  87. 'django.template.context_processors.request',
  88. 'django.contrib.auth.context_processors.auth',
  89. 'django.contrib.messages.context_processors.messages',
  90. ],
  91. },
  92. },
  93. ]
  94. WSGI_APPLICATION = 'ks.wsgi.application'
  95. # Database
  96. # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
  97. DATABASES = {
  98. 'default': {
  99. 'ENGINE': 'django.db.backends.mysql',
  100. 'NAME': 'ks',
  101. 'USER': 'root',
  102. 'PASSWORD': 'root',
  103. 'HOST': '127.0.0.1',
  104. 'PORT': 3306,
  105. }
  106. }
  107. # Password validation
  108. # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
  109. AUTH_PASSWORD_VALIDATORS = [
  110. {
  111. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  112. },
  113. {
  114. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  115. },
  116. {
  117. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  118. },
  119. {
  120. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  121. },
  122. ]
  123. # Internationalization
  124. # https://docs.djangoproject.com/en/2.2/topics/i18n/
  125. LANGUAGE_CODE = 'zh-hans'
  126. TIME_ZONE = 'Asia/Shanghai'
  127. USE_I18N = True
  128. USE_L10N = True
  129. USE_TZ = False
  130. # Static files (CSS, JavaScript, Images)
  131. # https://docs.djangoproject.com/en/2.2/howto/static-files/
  132. STATIC_URL = '/static/'
  133. MEDIA_URL = '/media/'
  134. MEDIA_ROOT = os.path.join(BASE_DIR, "uis/media/")
  135. UIS_URL = '/'
  136. UIS_ROOT = os.path.join(BASE_DIR, "uis/")
  137. JWT_AUTH = {
  138. 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=30),
  139. 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=360),
  140. 'JWT_ALLOW_REFRESH': True,
  141. }
  142. REST_FRAMEWORK = {
  143. 'DEFAULT_PERMISSION_CLASSES': (
  144. 'rest_framework.permissions.AllowAny',
  145. ),
  146. 'DEFAULT_AUTHENTICATION_CLASSES': (
  147. 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
  148. #'rest_framework.authentication.SessionAuthentication',
  149. #'rest_framework.authentication.BasicAuthentication',
  150. ),
  151. 'DEFAULT_PARSER_CLASSES': (
  152. 'rest_framework.parsers.JSONParser',
  153. 'rest_framework.parsers.FormParser',
  154. 'rest_framework.parsers.MultiPartParser'
  155. ),
  156. 'DEFAULT_RENDERER_CLASSES': (
  157. 'rest_framework.renderers.JSONRenderer',
  158. # 'rest_framework.renderers.BrowsableAPIRenderer',
  159. ),
  160. 'DEFAULT_FILTER_BACKENDS': (
  161. 'django_filters.rest_framework.DjangoFilterBackend',
  162. ),
  163. #'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
  164. 'DEFAULT_PAGINATION_CLASS': 'utils.pagination.CustomPagination',
  165. #'EXCEPTION_HANDLER': 'rest_framework.views.exception_handler',
  166. 'EXCEPTION_HANDLER': 'utils.handler.custom_exception_handler',
  167. 'PAGE_SIZE': 10,
  168. 'DATETIME_FORMAT': "%Y-%m-%d %H:%M:%S",
  169. 'NON_FIELD_ERRORS_KEY': "error", # 序列化器错误KEY名称
  170. }
  171. try:
  172. from ks.local_settings import *
  173. except ImportError:
  174. pass