123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- """
- Django settings for meib project.
- Generated by 'django-admin startproject' using Django 1.11.11.
- For more information on this file, see
- https://docs.djangoproject.com/en/1.11/topics/settings/
- For the full list of settings and their values, see
- https://docs.djangoproject.com/en/1.11/ref/settings/
- """
- import os
- # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- # Quick-start development settings - unsuitable for production
- # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
- # SECURITY WARNING: keep the secret key used in production secret!
- SECRET_KEY = '=&u2a!cp6*4i=$140mw^m_+2%ko82r+o*camh&=12mg2s+m%y0'
- # SECURITY WARNING: don't run with debug turned on in production!
- DEBUG = True
- ALLOWED_HOSTS = ['*']
- # Application definition
- import sys
- #告诉系统apps作为了子应用的新的导包路径
- sys.path.insert(1,os.path.join(BASE_DIR,'apps'))
- # import sys
- #告诉系统apps作为了子应用的新的导包路径
- sys.path.insert(0,os.path.join(BASE_DIR,'apps'))
- sys.path.insert(1,BASE_DIR)
- print(sys.path)
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'rest_framework',
- 'django_filters',
- 'corsheaders',
- 'erp.apps.ErpConfig', #ERP单据
- 'users.apps.UsersConfig', #登录
- 'tx.apps.TxConfig', #天玺应用
- 'bg.apps.BgConfig', #报工
- 'bj.apps.BjConfig', #报价
- 'bsdata.apps.BsdataConfig', #基础资料
- ]
- MIDDLEWARE = [
- 'django.middleware.security.SecurityMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.middleware.common.CommonMiddleware',
- 'corsheaders.middleware.CorsMiddleware',
- # 'django.middleware.csrf.CsrfViewMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
- 'django.middleware.clickjacking.XFrameOptionsMiddleware',
- # 'utils.middleware.middleware',#用户验证中间件
- ]
- ROOT_URLCONF = 'obj.urls'
- TEMPLATES = [
- {
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
- 'DIRS': [os.path.join(BASE_DIR,'templates')],
- 'APP_DIRS': True,
- 'OPTIONS': {
- 'context_processors': [
- 'django.template.context_processors.debug',
- 'django.template.context_processors.request',
- 'django.contrib.auth.context_processors.auth',
- 'django.contrib.messages.context_processors.messages',
- ],
- },
- },
- ]
- WSGI_APPLICATION = 'obj.wsgi.application'
- # Database
- # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
- # DATABASES = {
- # 'default': {
- # 'ENGINE': 'django.db.backends.sqlite3',
- # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
- # }
- # }
- # 配置连接数据库
- # DATABASES = {
- # # 'default': {
- # # 'ENGINE': 'django.db.backends.sqlite3',
- # # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
- # # }
- # 'default': {
- # 'NAME': 'DB_2019',
- # 'ENGINE': 'sql_server.pyodbc',
- # 'HOST': '127.0.0.1',
- # 'USER': 'sa',
- # 'PASSWORD': '123456',
- # 'PORT': '1433', # Set to empty string for default. Not used with sqlite3.
- # 'OPTIONS': {
- # 'host_is_server': True,
- # 'dsn': 'rencuiliang',##需要在电脑上使用odbc创建数据源odbc_jlad
- # },
- # }
- # }
- DATABASES = {
- 'default': {
- 'ENGINE': 'sql_server.pyodbc',
- 'NAME': 'DB_01',
- 'USER': 'sa',
- 'PASSWORD': 'nice1688**',
- 'HOST': '120.24.164.219',
- 'PORT': '1433',
- 'OPTIONS': {
- 'driver': 'SQL Server Native Client 10.0',
- },
- },
- }
- # 正式
- # DATABASES = {
- # 'default': {
- # 'ENGINE': 'sql_server.pyodbc',
- # 'NAME': 'db_tmb',
- # 'USER': 'SA',
- # 'PASSWORD': 'NBaws1q2w',
- # 'HOST': '127.0.0.1',
- # 'PORT': '1433',
- # 'OPTIONS': {
- # 'driver': 'SQL Server Native Client 10.0',
- # },
- # },
- # }
- DATABASE_CONNECTION_POOLING = True
- # Password validation
- # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
- AUTH_PASSWORD_VALIDATORS = [
- {
- 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
- },
- ]
- # Internationalization
- # https://docs.djangoproject.com/en/1.11/topics/i18n/
- LANGUAGE_CODE = 'en-us'
- TIME_ZONE = 'UTC'
- USE_I18N = True
- USE_L10N = True
- USE_TZ = True
- # Static files (CSS, JavaScript, Images)
- # https://docs.djangoproject.com/en/1.11/howto/static-files/
- STATIC_URL = '/static/'
- STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]
- #配置访问日志
- LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': False, # 是否禁用已经存在的日志器
- 'formatters': { # 日志信息显示的格式
- 'verbose': {
- 'format': '%(levelname)s %(asctime)s %(module)s %(lineno)d %(message)s'
- },
- 'simple': {
- 'format': '%(levelname)s %(module)s %(lineno)d %(message)s'
- },
- },
- 'filters': { # 对日志进行过滤
- 'require_debug_true': { # django在debug模式下才输出日志
- '()': 'django.utils.log.RequireDebugTrue',
- },
- },
- 'handlers': { # 日志处理方法
- 'console': { # 向终端中输出日志
- 'level': 'INFO',
- 'filters': ['require_debug_true'],
- 'class': 'logging.StreamHandler',
- 'formatter': 'simple'
- },
- 'file': { # 向文件中输出日志
- 'level': 'INFO',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(os.path.dirname(BASE_DIR), 'logs/hwj.log'), # 日志文件的位置
- 'maxBytes': 100 * 1024 * 1024,#输出日志大小,以字节为单位,也就是一个文件只能存放这个打数据的,超过会新增
- 'backupCount': 10,#最多超过生成10个文件
- 'formatter': 'verbose'
- },
- },
- 'loggers': { # 日志器
- 'django': { # 定义了一个名为django的日志器
- 'handlers': ['console', 'file'], # 可以同时向终端与文件中输出日志
- 'propagate': True, # 是否继续传递日志信息
- 'level': 'INFO', # 日志器接收的最低日志级别,INFO < debug < warn < error
- },
- }
- }
- # 指定静态文件的收集位置
- STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
- # 指定每页数量一览表
- PAGE_SIZE = 100
- # 指定每页数量ie文件明细表
- PAGE_SIZE_IE = 100
- # 指定用户模型
- AUTH_USER_MODEL = 'users.User'
- #指定认证后端
- AUTHENTICATION_BACKENDS = ['utils.authenticate.MyAuthenticateBackend']
- # 登录金牌认证配置==================================================================================================
- # 配置jwt登录验证
- REST_FRAMEWORK = {
- 'DEFAULT_AUTHENTICATION_CLASSES': (
- 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
- 'rest_framework.authentication.SessionAuthentication', #正式用户
- # 'rest_framework.authentication.BasicAuthentication', #测试用户
- ),
- 'DEFAULT_PERMISSION_CLASSES': (
- 'rest_framework.permissions.IsAuthenticated', #用户权限
- # 'rest_framework.permissions.AllowAny', #任何用户权限S
- # 'rest_framework.permissions.IsAdminUser', #管理员权限
- ),
- # 分页设置
- 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
- 'PAGE_SIZE': 4,
- # 过滤设置
- # 6,过滤
- 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',)
- }
- import datetime
- JWT_AUTH = {
- 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),# 设置登录的有效时间
- 'JWT_RESPONSE_PAYLOAD_HANDLER':'users.utils.jwt_response_payload_handler',## 设置登录成功的返回值
- 'JWT_ALLOW_REFRESH': True,#设置可以利用旧的token刷新得到新的token
- }
- # CORS
- CORS_ORIGIN_WHITELIST = (
- 'http://127.0.0.1:8080',
- 'http://127.0.0.1:8080',
- 'http://127.0.0.1:8811',
- 'http://172.16.20.5:8811',
- 'http://localhost:8080'
- )
- CORS_ALLOW_CREDENTIALS = True # 允许携带cookie
- # 跨域增加忽略
- # CORS_ALLOW_CREDENTIALS = True
- CORS_ORIGIN_ALLOW_ALL = True
- # CORS_ORIGIN_WHITELIST = ()
- CORS_ALLOW_METHODS = (
- 'DELETE',
- 'GET',
- 'OPTIONS',
- 'PATCH',
- 'POST',
- 'PUT',
- 'VIEW',
- )
- CORS_ALLOW_HEADERS = (
- 'accept',
- 'accept-encoding',
- 'authorization',
- 'content-type',
- 'dnt',
- 'origin',
- 'user-agent',
- 'x-csrftoken',
- 'x-requested-with',
- )
|