settings.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. """
  2. Django settings for gameHall project.
  3. Generated by 'django-admin startproject' using Django 2.1.3.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/2.1/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/2.1/ref/settings/
  8. """
  9. import os
  10. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  11. import sys
  12. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  13. sys.path.insert(0, os.path.join(BASE_DIR, 'gameHall'))
  14. # 把extra_apps文件夹添加到搜索目录中
  15. sys.path.insert(0, os.path.join(BASE_DIR, 'extra_apps'))
  16. # Quick-start development settings - unsuitable for production
  17. # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
  18. # SECURITY WARNING: keep the secret key used in production secret!
  19. SECRET_KEY = 'm02=(nifvtbsq+v&s(%_ft=@&_p+tg7s3(^fchb$m-pvb4+w6o'
  20. # SECURITY WARNING: don't run with debug turned on in production!
  21. DEBUG = True
  22. ALLOWED_HOSTS = ['*']
  23. # Application definition
  24. INSTALLED_APPS = [
  25. 'django.contrib.admin',
  26. 'django.contrib.auth',
  27. 'django.contrib.contenttypes',
  28. 'django.contrib.sessions',
  29. 'django.contrib.messages',
  30. 'django.contrib.staticfiles',
  31. 'rest_framework',
  32. 'rest_framework.authtoken',
  33. # 解决跨域
  34. 'corsheaders',
  35. 'xadmin',
  36. 'crispy_forms', # 注意crispy_forms之间是下划线隔开,不是横线
  37. 'reversion', # 添加(可选)
  38. 'app'
  39. ]
  40. MIDDLEWARE = [
  41. 'django.middleware.security.SecurityMiddleware',
  42. 'django.contrib.sessions.middleware.SessionMiddleware',
  43. 'django.middleware.common.CommonMiddleware',
  44. 'corsheaders.middleware.CorsMiddleware',
  45. # 测试关掉post
  46. # 'django.middleware.csrf.CsrfViewMiddleware',
  47. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  48. 'django.contrib.messages.middleware.MessageMiddleware',
  49. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  50. ]
  51. # REST_FRAMEWORK的配置
  52. REST_FRAMEWORK = {
  53. # 'DEFAULT_PERMISSION_CLASSES': (
  54. # 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',
  55. # 'rest_framework.permissions.IsAuthenticated',
  56. # 'rest_framework.permissions.AllowAny',
  57. # ),
  58. # 'DEFAULT_AUTHENTICATION_CLASSES': (
  59. # 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
  60. # 'rest_framework.authentication.SessionAuthentication',
  61. # 'rest_framework.authentication.TokenAuthentication',
  62. # 'rest_framework.authentication.BasicAuthentication',
  63. # ),
  64. # 分页显示
  65. 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
  66. 'PAGE_SIZE': 10,
  67. # 配置过滤
  68. 'DEFAULT_FILTER_BACKENDS': (
  69. 'django_filters.rest_framework.DjangoFilterBackend', 'rest_framework.filters.SearchFilter'),
  70. }
  71. ROOT_URLCONF = 'gameHall.urls'
  72. import datetime
  73. JWT_AUTH = {
  74. 'JWT_AUTH_HEADER_PREFIX': 'Token',
  75. 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=30),
  76. 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=365),
  77. }
  78. TEMPLATES = [
  79. {
  80. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  81. 'DIRS': [os.path.join(BASE_DIR, 'templates')]
  82. ,
  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 = 'gameHall.wsgi.application'
  95. # Database
  96. # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
  97. DATABASES = {
  98. 'default': {
  99. 'ENGINE': 'django.db.backends.sqlite3',
  100. 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  101. }
  102. # 'default': {
  103. # 'ENGINE': 'django.db.backends.mysql',
  104. # 'NAME': 'gamehall',
  105. # 'HOST': 'localhost',
  106. # 'PORT': '3306',
  107. # 'USER': 'root',
  108. # 'PASSWORD': '123456',
  109. # },
  110. # # 开发
  111. # 'dev': {
  112. # 'ENGINE': 'django.db.backends.mysql',
  113. # 'NAME': 'gamehall',
  114. # 'HOST': 'localhost',
  115. # 'PORT': '3306',
  116. # 'USER': 'root',
  117. # 'PASSWORD': '123',
  118. # },
  119. # # 正式
  120. # 'pro': {
  121. # 'ENGINE': 'django.db.backends.mysql',
  122. # 'NAME': 'gamehall',
  123. # 'HOST': 'localhost',
  124. # 'PORT': '3306',
  125. # 'USER': 'root',
  126. # 'PASSWORD': '123456',
  127. # },
  128. }
  129. # DATABASE_ROUTERS = ['gameHall.database_router.DatabaseAppsRouter']
  130. # DATABASE_APPS_MAPPING = {
  131. # # example:
  132. # # 'app_name':'database_name',
  133. # 'app': 'default',
  134. # # 正式环境切换
  135. # # 'app': 'pro',
  136. # }
  137. # Password validation
  138. # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
  139. AUTH_PASSWORD_VALIDATORS = [
  140. {
  141. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  142. },
  143. {
  144. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  145. },
  146. {
  147. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  148. },
  149. {
  150. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  151. },
  152. ]
  153. # Internationalization
  154. # https://docs.djangoproject.com/en/2.1/topics/i18n/
  155. LANGUAGE_CODE = 'zh-Hans'
  156. TIME_ZONE = 'Asia/Shanghai'
  157. USE_I18N = True
  158. USE_L10N = True
  159. USE_TZ = True
  160. # Static files (CSS, JavaScript, Images)
  161. # https://docs.djangoproject.com/en/2.1/howto/static-files/
  162. STATIC_URL = '/static/'
  163. CORS_ALLOW_CREDENTIALS = True
  164. CORS_ORIGIN_ALLOW_ALL = True
  165. CORS_ALLOW_METHODS = (
  166. 'DELETE',
  167. 'GET',
  168. 'OPTIONS',
  169. 'PATCH',
  170. 'POST',
  171. 'PUT',
  172. 'VIEW',
  173. )
  174. CORS_ALLOW_HEADERS = (
  175. 'XMLHttpRequest',
  176. 'X_FILENAME',
  177. 'accept-encoding',
  178. 'authorization',
  179. 'content-type',
  180. 'dnt',
  181. 'origin',
  182. 'user-agent',
  183. 'x-csrftoken',
  184. 'x-requested-with',
  185. 'Pragma',
  186. )
  187. MEDIA_URL = "/media/"
  188. MEDIA_ROOT = os.path.join(BASE_DIR, "media")
  189. CKEDITOR_UPLOAD_PATH = "article_images"