dev.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. print(sys.path)
  28. INSTALLED_APPS = [
  29. 'django.contrib.admin',
  30. 'django.contrib.auth',
  31. 'django.contrib.contenttypes',
  32. 'django.contrib.sessions',
  33. 'django.contrib.messages',
  34. 'django.contrib.staticfiles',
  35. 'rest_framework',
  36. 'django_filters',
  37. 'corsheaders',
  38. 'erp.apps.ErpConfig', #ERP单据
  39. 'users.apps.UsersConfig', #登录
  40. 'tx.apps.TxConfig', #天玺应用
  41. 'bg.apps.BgConfig', #报工
  42. 'bj.apps.BjConfig', #报价
  43. 'bsdata.apps.BsdataConfig', #基础资料
  44. ]
  45. MIDDLEWARE = [
  46. 'django.middleware.security.SecurityMiddleware',
  47. 'django.contrib.sessions.middleware.SessionMiddleware',
  48. 'django.middleware.common.CommonMiddleware',
  49. 'corsheaders.middleware.CorsMiddleware',
  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 = 'obj.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 = 'obj.wsgi.application'
  73. # Database
  74. # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
  75. # DATABASES = {
  76. # 'default': {
  77. # 'ENGINE': 'django.db.backends.sqlite3',
  78. # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  79. # }
  80. # }
  81. # 配置连接数据库
  82. # DATABASES = {
  83. # # 'default': {
  84. # # 'ENGINE': 'django.db.backends.sqlite3',
  85. # # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  86. # # }
  87. # 'default': {
  88. # 'NAME': 'DB_2019',
  89. # 'ENGINE': 'sql_server.pyodbc',
  90. # 'HOST': '127.0.0.1',
  91. # 'USER': 'sa',
  92. # 'PASSWORD': '123456',
  93. # 'PORT': '1433', # Set to empty string for default. Not used with sqlite3.
  94. # 'OPTIONS': {
  95. # 'host_is_server': True,
  96. # 'dsn': 'rencuiliang',##需要在电脑上使用odbc创建数据源odbc_jlad
  97. # },
  98. # }
  99. # }
  100. DATABASES = {
  101. 'default': {
  102. 'ENGINE': 'sql_server.pyodbc',
  103. 'NAME': 'DB_01',
  104. 'USER': 'sa',
  105. 'PASSWORD': 'nice1688**',
  106. 'HOST': '120.24.164.219',
  107. 'PORT': '1433',
  108. 'OPTIONS': {
  109. 'driver': 'SQL Server Native Client 10.0',
  110. },
  111. },
  112. }
  113. # 正式
  114. # DATABASES = {
  115. # 'default': {
  116. # 'ENGINE': 'sql_server.pyodbc',
  117. # 'NAME': 'db_tmb',
  118. # 'USER': 'SA',
  119. # 'PASSWORD': 'NBaws1q2w',
  120. # 'HOST': '127.0.0.1',
  121. # 'PORT': '1433',
  122. # 'OPTIONS': {
  123. # 'driver': 'SQL Server Native Client 10.0',
  124. # },
  125. # },
  126. # }
  127. DATABASE_CONNECTION_POOLING = True
  128. # Password validation
  129. # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
  130. AUTH_PASSWORD_VALIDATORS = [
  131. {
  132. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  133. },
  134. {
  135. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  136. },
  137. {
  138. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  139. },
  140. {
  141. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  142. },
  143. ]
  144. # Internationalization
  145. # https://docs.djangoproject.com/en/1.11/topics/i18n/
  146. LANGUAGE_CODE = 'en-us'
  147. TIME_ZONE = 'UTC'
  148. USE_I18N = True
  149. USE_L10N = True
  150. USE_TZ = True
  151. # Static files (CSS, JavaScript, Images)
  152. # https://docs.djangoproject.com/en/1.11/howto/static-files/
  153. STATIC_URL = '/static/'
  154. STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]
  155. #配置访问日志
  156. LOGGING = {
  157. 'version': 1,
  158. 'disable_existing_loggers': False, # 是否禁用已经存在的日志器
  159. 'formatters': { # 日志信息显示的格式
  160. 'verbose': {
  161. 'format': '%(levelname)s %(asctime)s %(module)s %(lineno)d %(message)s'
  162. },
  163. 'simple': {
  164. 'format': '%(levelname)s %(module)s %(lineno)d %(message)s'
  165. },
  166. },
  167. 'filters': { # 对日志进行过滤
  168. 'require_debug_true': { # django在debug模式下才输出日志
  169. '()': 'django.utils.log.RequireDebugTrue',
  170. },
  171. },
  172. 'handlers': { # 日志处理方法
  173. 'console': { # 向终端中输出日志
  174. 'level': 'INFO',
  175. 'filters': ['require_debug_true'],
  176. 'class': 'logging.StreamHandler',
  177. 'formatter': 'simple'
  178. },
  179. 'file': { # 向文件中输出日志
  180. 'level': 'INFO',
  181. 'class': 'logging.handlers.RotatingFileHandler',
  182. 'filename': os.path.join(os.path.dirname(BASE_DIR), 'logs/hwj.log'), # 日志文件的位置
  183. 'maxBytes': 100 * 1024 * 1024,#输出日志大小,以字节为单位,也就是一个文件只能存放这个打数据的,超过会新增
  184. 'backupCount': 10,#最多超过生成10个文件
  185. 'formatter': 'verbose'
  186. },
  187. },
  188. 'loggers': { # 日志器
  189. 'django': { # 定义了一个名为django的日志器
  190. 'handlers': ['console', 'file'], # 可以同时向终端与文件中输出日志
  191. 'propagate': True, # 是否继续传递日志信息
  192. 'level': 'INFO', # 日志器接收的最低日志级别,INFO < debug < warn < error
  193. },
  194. }
  195. }
  196. # 指定静态文件的收集位置
  197. STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
  198. # 指定每页数量一览表
  199. PAGE_SIZE = 100
  200. # 指定每页数量ie文件明细表
  201. PAGE_SIZE_IE = 100
  202. # 指定用户模型
  203. AUTH_USER_MODEL = 'users.User'
  204. #指定认证后端
  205. AUTHENTICATION_BACKENDS = ['utils.authenticate.MyAuthenticateBackend']
  206. # 登录金牌认证配置==================================================================================================
  207. # 配置jwt登录验证
  208. REST_FRAMEWORK = {
  209. 'DEFAULT_AUTHENTICATION_CLASSES': (
  210. 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
  211. 'rest_framework.authentication.SessionAuthentication', #正式用户
  212. # 'rest_framework.authentication.BasicAuthentication', #测试用户
  213. ),
  214. 'DEFAULT_PERMISSION_CLASSES': (
  215. 'rest_framework.permissions.IsAuthenticated', #用户权限
  216. # 'rest_framework.permissions.AllowAny', #任何用户权限S
  217. # 'rest_framework.permissions.IsAdminUser', #管理员权限
  218. ),
  219. # 分页设置
  220. 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
  221. 'PAGE_SIZE': 4,
  222. # 过滤设置
  223. # 6,过滤
  224. 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',)
  225. }
  226. import datetime
  227. JWT_AUTH = {
  228. 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),# 设置登录的有效时间
  229. 'JWT_RESPONSE_PAYLOAD_HANDLER':'users.utils.jwt_response_payload_handler',## 设置登录成功的返回值
  230. 'JWT_ALLOW_REFRESH': True,#设置可以利用旧的token刷新得到新的token
  231. }
  232. # CORS
  233. CORS_ORIGIN_WHITELIST = (
  234. 'http://127.0.0.1:8080',
  235. 'http://127.0.0.1:8080',
  236. 'http://127.0.0.1:8811',
  237. 'http://172.16.20.5:8811',
  238. 'http://localhost:8080'
  239. )
  240. CORS_ALLOW_CREDENTIALS = True # 允许携带cookie
  241. # 跨域增加忽略
  242. # CORS_ALLOW_CREDENTIALS = True
  243. CORS_ORIGIN_ALLOW_ALL = True
  244. # CORS_ORIGIN_WHITELIST = ()
  245. CORS_ALLOW_METHODS = (
  246. 'DELETE',
  247. 'GET',
  248. 'OPTIONS',
  249. 'PATCH',
  250. 'POST',
  251. 'PUT',
  252. 'VIEW',
  253. )
  254. CORS_ALLOW_HEADERS = (
  255. 'accept',
  256. 'accept-encoding',
  257. 'authorization',
  258. 'content-type',
  259. 'dnt',
  260. 'origin',
  261. 'user-agent',
  262. 'x-csrftoken',
  263. 'x-requested-with',
  264. )