text: """
  Django settings for meiduo 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
  import sys
  import datetime
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
  
  
  # 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 = 'ujq_3r%lyywr9vdr)#(qp@*hz&v6mt*7w_92+^zln61tatxl&_'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  # DEBUG = True  # 开发阶段
  DEBUG = False   # 上线阶段
  
  ALLOWED_HOSTS = [
      '*',
      'www.meiduo.site',
      '127.0.0.1']
  
  
  # Application definition
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
  
      # 导入的应用
      'haystack',   # 全文检索
      'django_crontab',  # 定时调度任务
      'rest_framework',
      'corsheaders',
  
  
      # 自定义的应用， 如果有迁移建表必须要登记
      'users.apps.UsersConfig',
      'verifications.apps.VerificationsConfig',
      'oauth.apps.OauthConfig',
      'contents.apps.ContentsConfig',
      'areas.apps.AreasConfig',
      'goods.apps.GoodsConfig',
      'orders.apps.OrdersConfig',
      'payment.apps.PaymentConfig',
  ]
  
  MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
      'corsheaders.middleware.CorsMiddleware',
  ]
  
  ROOT_URLCONF = 'meiduo.urls'
  
  # django自带模板渲染
  # TEMPLATES = [
  #     {
  #         'BACKEND': 'django.template.backends.django.DjangoTemplates',
  #         'DIRS': [],
  #         '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',
  #             ],
  #         },
  #     },
  # ]
  
  # 配置jinja2模板使用
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.jinja2.Jinja2',
          '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',
              ],
              'environment': 'meiduo.utils.jinja2_env.jinja2_environment',
          },
      },
  ]
  
  WSGI_APPLICATION = 'meiduo.wsgi.application'
  
  
  # Database
  # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
  # django默认数据库
  # DATABASES = {
  #     'default': {
  #         'ENGINE': 'django.db.backends.sqlite3',
  #         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  #     }
  # }
  
  DATABASES = {
      'default': {  # 写， 主机
          'ENGINE': 'django.db.backends.mysql',
          'HOST': '127.0.0.1',
          'PORT': 3306,
          'USER': 'meiduo',
          'PASSWORD': '123456',
          'NAME': 'meiduo',
      },
      'slave': {  # 读（从机）
          'ENGINE': 'django.db.backends.mysql',
          'HOST': '127.0.0.1',
          'PORT': 8306,
          'USER': 'root',   #　从服务器的用户名
          'PASSWORD': 'mysql',
          'NAME': 'meiduo'
      },
  }
  
  # 指定读写分离的配置
  DATABASE_ROUTERS = ['meiduo.utils.db_router.MasterSlaveDBRouter']
  
  
  CACHES = {
      "default": { # 默认
          "BACKEND": "django_redis.cache.RedisCache",
          "LOCATION": "redis://127.0.0.1:6379/0",
          "OPTIONS": {
              "CLIENT_CLASS": "django_redis.client.DefaultClient",
          }
      },
      "session": { # session
          "BACKEND": "django_redis.cache.RedisCache",
          "LOCATION": "redis://127.0.0.1:6379/1",
          "OPTIONS": {
              "CLIENT_CLASS": "django_redis.client.DefaultClient",
          }
      },
      'verifications': {
          'BACKEND': 'django_redis.cache.RedisCache',
          'LOCATION': 'redis://127.0.0.1:6379/2',
          'OPTIONS': {
              'CLIENT_CLASS': 'django_redis.client.DefaultClient',
          }
      },
      'history': {
          'BACKEND': 'django_redis.cache.RedisCache',
          'LOCATION': 'redis://127.0.0.1:6379/3',
          'OPTIONS': {
              'CLIENT_CLASS': 'django_redis.client.DefaultClient',
          }
      },
      'carts': {
          'BACKEND': 'django_redis.cache.RedisCache',
          'LOCATION': 'redis://127.0.0.1:6379/4',
          'OPTIONS': {
              'CLIENT_CLASS': 'django_redis.client.DefaultClient',
          }
      },
  }
  # 指定session存储的模式为本机内存(更准确是内存模式),不指定默认存储在数据库db(已经在INSTALLED_APPS上注册),
  SESSION_ENGINE = "django.contrib.sessions.backends.cache"
  # 实际保存在本机内存不易与不同服务器的共享, 指定存储的Redis数据库'session'
  SESSION_CACHE_ALIAS = "session"
  
  
  
  # 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'
  LANGUAGE_CODE = 'zh-hans'
  
  # TIME_ZONE = 'UTC'
  TIME_ZONE = 'Asia/Shanghai'
  
  USE_I18N = True
  
  USE_L10N = True
  
  # USE_TZ = True 默认是True， 使用世界时区
  
  # USE_TZ = False  # 修改为False， 使用定义的TIME_ZONE
  USE_TZ = True  # 修改为False， 使用定义的TIME_ZONE
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/1.11/howto/static-files/
  
  # STATIC_URL 是URL的资源路径,以/abc/开头的判断为静态请求,将查找到STATICFILES_DIRS指定的文件夹,
  # 按照url资源路径的剩余部分去STATICFILES_DIRS文件夹下查找
  STATIC_URL = '/static/'
  STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
  
  # 用户登录校验失败的人重定向到登录页面
  LOGIN_URL = '/login/'
  
  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/meiduo.log'),  # 日志文件的位置
              'maxBytes': 300 * 1024 * 1024,
              'backupCount': 10,
              'formatter': 'verbose'
          },
      },
      'loggers': {  # 日志器
          'django': {  # 定义了一个名为django的日志器
              'handlers': ['console', 'file'],  # 可以同时向终端与文件中输出日志
              'propagate': True,  # 是否继续传递日志信息
              'level': 'INFO',  # 日志器接收的最低日志级别
          },
      }
  }
  
  AUTH_USER_MODEL = 'users.User'
  
  # 該參數設定session的保存時間，若要修改狀態保存時間，就修改此處
  SESSION_COOKIE_AGE = 60 * 60 * 48
  
  # 修改认证类后，想要生效， 必须在配置上注册
  # 加载顺序：global.setting  -->setting.dev  后写的会覆盖之前的配置设置
  AUTHENTICATION_BACKENDS = ['users.utils.ManyUser']
  
  
  # global_setting 中的邮箱配置
  # EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  # Host for sending email.
  # EMAIL_HOST = 'localhost'
  # Port for sending email.
  # EMAIL_PORT = 25
  # Whether to send SMTP 'Date' header in the local time zone or in UTC.
  # EMAIL_USE_LOCALTIME = False
  # EMAIL_HOST_USER = ''
  # EMAIL_HOST_PASSWORD = ''
  # EMAIL_USE_TLS = False
  # EMAIL_USE_SSL = False
  # EMAIL_SSL_CERTFILE = None
  # EMAIL_SSL_KEYFILE = None
  # EMAIL_TIMEOUT = None
  
  
  EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'  # 指定邮件后端
  EMAIL_HOST = 'smtp.163.com'  # 发邮件主机
  EMAIL_PORT = 25  # 发邮件端口
  EMAIL_HOST_USER = 'itcast99@163.com'  # 授权的邮箱
  EMAIL_HOST_PASSWORD = 'python99'  # 邮箱授权时获得的密码，非注册登录密码
  EMAIL_FROM = '美多商城<itcast99@163.com>'  # 发件人抬头
  
  # 校验邮箱的拼接
  # EMAIL_VERIFY_URL = 'http://www.meiduo.site:8000/emails/verifications/'   # 开发阶段
  EMAIL_VERIFY_URL = 'http://www.meiduo.site:80/emails/verifications/'   # 生产阶段
  
  
  # Roor是指定本项目/本电脑的的资源
  MEDIA_ROOT = ''
  # URL是指定远程的服务器资源的， 使用http协议沟通数据
  # 单独这一句也可以， 这样模板文件在image.url时拼接的路径就是FDFS_BASE_URL + file_id, 可以访问到文件的正确远程路径
  # FDFS_BASE_URL = 'http://192.168.234.129:8888/'
  
  # 自定义的文件存储类，要使用前需要配置，在该类中定义拼接URL的方式
  # DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
  DEFAULT_FILE_STORAGE = 'meiduo.apps.contents.utils.ImgFastStorage'
  
  
  # Haystack
  HAYSTACK_CONNECTIONS = {
      'default': {
          'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
          'URL': 'http://192.168.234.129:9200/', # Elasticsearch服务器ip地址，端口号固定为9200
          'INDEX_NAME': 'meiduo_mall', # Elasticsearch建立的索引库的名称，
      },
  }
  
  # 当添加、修改、删除数据时，自动生成索引
  HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
  
  # 每此查询的分页条数
  HAYSTACK_SEARCH_RESULTS_PER_PAGE = 5
  
  # 支付配置
  ALIPAY_APPID = '2016101000651850'
  ALIPAY_DEBUG = True  # 表示是沙箱环境还是真实支付环境
  ALIPAY_URL = 'https://openapi.alipaydev.com/gateway.do'
  # ALIPAY_RETURN_URL = 'http://www.meiduo.site:8000/payment/status/'   # 开发阶段
  ALIPAY_RETURN_URL = 'http://www.meiduo.site:80/payment/status/'  # 生产阶段
  
  
  CRONJOBS = [
      # 每1分钟生成一次首页静态文件
      ('*/1 * * * *', 'contents.crons.generate_static_index_html', '>> ' + os.path.join(os.path.dirname(BASE_DIR), 'logs/crontab.log'))
  ]
  
  CRONTAB_COMMAND_PREFIX = 'LANG_ALL=zh_cn.UTF-8'
  
  
  # 收集项目的所有静态文件
  STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
  
  
  # CORS
  CORS_ORIGIN_WHITELIST = (
      '127.0.0.1:8080',
      'localhost:8080',
      'www.meiduo.site:8080',
      'api.meiduo.site:8000'
  )
  CORS_ALLOW_CREDENTIALS = True  # 允许携带cookie
  
  # from rest_framework_jwt.authentication import
  # from rest_framework.authentication import
  REST_FRAMEWORK = {
      'DEFAULT_AUTHENTICATION_CLASSES': (
          # 默认是从上到下， 一个通过就通过
          # 全部不通过才会报错
          'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
          'rest_framework.authentication.SessionAuthentication',
          'rest_framework.authentication.BasicAuthentication',
      ),
  }
  # from rest_framework_jwt.settings import
  JWT_AUTH = {
      # 'JWT_VERIFY_EXPIRATION': False,  # 是否进行JWT校验
      # 'JWT_AUTH_HEADER_PREFIX': 'Authorization',  # 签发的token的 request头的名字
      'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
      'JWT_RESPONSE_PAYLOAD_HANDLER': 'meiduo_admin.utils.jwt_response.jwt_response_payload_handler',
  }
  
  # Fastfds 的配置文件路径
  FASTFDS_CONF_PATH = os.path.join(BASE_DIR, 'utils/fastfds/client.conf')
  