dev.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. """
  2. Django settings for meib project.
  3. Generated by 'django-admin startproject' using Django 1.11.11.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/1.11/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/1.11/ref/settings/
  8. """
  9. import os
  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/1.11/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = '=&u2a!cp6*4i=$140mw^m_+2%ko82r+o*camh&=12mg2s+m%y0'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = True
  18. ALLOWED_HOSTS = ['*']
  19. # Application definition
  20. import sys
  21. #告诉系统apps作为了子应用的新的导包路径
  22. sys.path.insert(1,os.path.join(BASE_DIR,'apps'))
  23. # import sys
  24. #告诉系统apps作为了子应用的新的导包路径
  25. sys.path.insert(0,os.path.join(BASE_DIR,'apps'))
  26. sys.path.insert(1,BASE_DIR)
  27. sys.path.insert(0,os.path.join(BASE_DIR,'apps/admin'))
  28. sys.path.insert(1,BASE_DIR)
  29. INSTALLED_APPS = [
  30. 'django.contrib.admin',
  31. 'django.contrib.auth',
  32. 'django.contrib.contenttypes',
  33. 'django.contrib.sessions',
  34. 'django.contrib.messages',
  35. 'django.contrib.staticfiles',
  36. 'rest_framework',
  37. 'corsheaders',
  38. 'bsdata.apps.BsdataConfig',#项目基础配置
  39. 'users.apps.UsersConfig', #用户模块
  40. 'topdev.apps.TopdevConfig',#顶部设置
  41. 'webnews.apps.WeblogoConfig',#顶部设置
  42. 'django_filters',
  43. ]
  44. MIDDLEWARE = [
  45. 'corsheaders.middleware.CorsMiddleware',
  46. 'django.middleware.common.CommonMiddleware',
  47. 'django.middleware.security.SecurityMiddleware',
  48. 'django.contrib.sessions.middleware.SessionMiddleware',
  49. 'django.middleware.common.CommonMiddleware',
  50. # 'django.middleware.csrf.CsrfViewMiddleware',
  51. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  52. 'django.contrib.messages.middleware.MessageMiddleware',
  53. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  54. # 'utils.middleware.middleware',#用户验证中间件
  55. ]
  56. ROOT_URLCONF = 'project.urls'
  57. TEMPLATES = [
  58. {
  59. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  60. 'DIRS': [os.path.join(BASE_DIR,'templates')],
  61. 'APP_DIRS': True,
  62. 'OPTIONS': {
  63. 'context_processors': [
  64. 'django.template.context_processors.debug',
  65. 'django.template.context_processors.request',
  66. 'django.contrib.auth.context_processors.auth',
  67. 'django.contrib.messages.context_processors.messages',
  68. ],
  69. },
  70. },
  71. ]
  72. WSGI_APPLICATION = 'project.wsgi.application'
  73. # 配置连接数据库
  74. DATABASES = {
  75. 'default': {
  76. 'ENGINE': 'django.db.backends.mysql',
  77. 'NAME': 'wn_web',
  78. 'USER': 'root',
  79. 'PASSWORD': 'root',
  80. 'HOST': '101.200.193.157',
  81. 'PORT': '3306',
  82. 'OPTIONS':{
  83. "init_command":"SET foreign_key_checks = 0;",
  84. }
  85. }
  86. }
  87. DATABASE_CONNECTION_POOLING = True
  88. # Password validation
  89. # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
  90. AUTH_PASSWORD_VALIDATORS = [
  91. {
  92. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  93. },
  94. {
  95. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  96. },
  97. {
  98. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  99. },
  100. {
  101. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  102. },
  103. ]
  104. # Internationalization
  105. # https://docs.djangoproject.com/en/1.11/topics/i18n/
  106. LANGUAGE_CODE = 'zh-hans'
  107. TIME_ZONE = 'Asia/Shanghai'
  108. USE_TZ = False
  109. USE_I18N = True
  110. USE_L10N = True
  111. # Static files (CSS, JavaScript, Images)
  112. # https://docs.djangoproject.com/en/1.11/howto/static-files/
  113. STATIC_URL = '/static/'
  114. STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]
  115. MEDIA_ROOT=os.path.join(BASE_DIR,r'static/uploads')
  116. #配置访问日志
  117. LOGGING = {
  118. 'version': 1,
  119. 'disable_existing_loggers': False, # 是否禁用已经存在的日志器
  120. 'formatters': { # 日志信息显示的格式
  121. 'verbose': {
  122. 'format': '%(levelname)s %(asctime)s %(module)s %(lineno)d %(message)s'
  123. },
  124. 'simple': {
  125. 'format': '%(levelname)s %(module)s %(lineno)d %(message)s'
  126. },
  127. },
  128. 'filters': { # 对日志进行过滤
  129. 'require_debug_true': { # django在debug模式下才输出日志
  130. '()': 'django.utils.log.RequireDebugTrue',
  131. },
  132. },
  133. 'handlers': { # 日志处理方法
  134. 'console': { # 向终端中输出日志
  135. 'level': 'INFO',
  136. 'filters': ['require_debug_true'],
  137. 'class': 'logging.StreamHandler',
  138. 'formatter': 'simple'
  139. },
  140. 'file': { # 向文件中输出日志
  141. 'level': 'INFO',
  142. 'class': 'logging.handlers.RotatingFileHandler',
  143. 'filename': os.path.join(os.path.dirname(BASE_DIR), 'logs/shop_logs.log'), # 日志文件的位置
  144. 'maxBytes': 100 * 1024 * 1024,#输出日志大小,以字节为单位,也就是一个文件只能存放这个打数据的,超过会新增
  145. 'backupCount': 10,#最多超过生成10个文件
  146. 'formatter': 'verbose'
  147. },
  148. },
  149. 'loggers': { # 日志器
  150. 'django': { # 定义了一个名为django的日志器
  151. 'handlers': ['console', 'file'], # 可以同时向终端与文件中输出日志
  152. 'propagate': True, # 是否继续传递日志信息
  153. 'level': 'INFO', # 日志器接收的最低日志级别,INFO < debug < warn < error
  154. },
  155. }
  156. }
  157. APPEND_SLASH = False
  158. # 指定静态文件的收集位置
  159. STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
  160. # 指定用户模型
  161. AUTH_USER_MODEL = 'users.User'
  162. # 配置七牛云=========================================================================================================
  163. QINIU_ACCESS_KEY = 'oT8JwPafdOewYYx2crMLkxmaDEX4NKLAMNrVTAcW' #七牛云账号密码管理面的ak
  164. QINIU_SECRET_KEY = 'H5C51pAfXUK4ovmWJbaeOlAplS-13ybaxxvT7oAi' #七牛云账号密码管理面的sk
  165. QINIU__UTL = 'http://qbv4c6unm.bkt.clouddn.com/' #七牛应用的域名
  166. # 要上传的空间
  167. BUCKET_NAME = 'eadasd' #七牛云应用名称
  168. QINIU_SECURE_URL = False #使用http
  169. #指定认证后端
  170. AUTHENTICATION_BACKENDS = ['utils.authenticate.MyAuthenticateBackend']
  171. # 登录金牌认证配置==================================================================================================
  172. # 配置jwt登录验证
  173. REST_FRAMEWORK = {
  174. 'DEFAULT_AUTHENTICATION_CLASSES': (
  175. 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
  176. 'rest_framework.authentication.SessionAuthentication', #正式用户
  177. # 'rest_framework.authentication.BasicAuthentication', #测试用户
  178. ),
  179. 'DEFAULT_PERMISSION_CLASSES': (
  180. # 'rest_framework.permissions.IsAuthenticated', #用户权限
  181. 'rest_framework.permissions.AllowAny', #任何用户权限S
  182. # 'rest_framework.permissions.IsAdminUser', #管理员权限
  183. ),
  184. # 分页设置
  185. 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
  186. 'PAGE_SIZE': 20,
  187. # 过滤设置
  188. # 6,过滤
  189. 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',)
  190. }
  191. import datetime
  192. JWT_AUTH = {
  193. 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),# 设置登录的有效时间
  194. 'JWT_RESPONSE_PAYLOAD_HANDLER':'users.utils.jwt_response_payload_handler',## 设置登录成功的返回值
  195. 'JWT_ALLOW_REFRESH': True,#设置可以利用旧的token刷新得到新的token
  196. }
  197. # 跨域请求
  198. # CORS
  199. CORS_ORIGIN_WHITELIST = (
  200. 'http://127.0.0.1:8800',
  201. 'http://127.0.0.1:8800',
  202. 'http://101.200.193.157:8800',
  203. 'http://localhost:8800'
  204. )
  205. CORS_ALLOW_CREDENTIALS = True # 允许携带cookie
  206. # 跨域增加忽略
  207. # CORS_ALLOW_CREDENTIALS = True
  208. CORS_ORIGIN_ALLOW_ALL = True
  209. # CORS_ORIGIN_WHITELIST = ()
  210. CORS_ALLOW_METHODS = (
  211. 'DELETE',
  212. 'GET',
  213. 'OPTIONS',
  214. 'PATCH',
  215. 'POST',
  216. 'PUT',
  217. 'VIEW',
  218. )
  219. CORS_ALLOW_HEADERS = (
  220. 'accept',
  221. 'accept-encoding',
  222. 'authorization',
  223. 'content-type',
  224. 'dnt',
  225. 'origin',
  226. 'user-agent',
  227. 'x-csrftoken',
  228. 'x-requested-with',
  229. )