text: """
  Django settings for ManyBeautifulMall 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 datetime
  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__)))
  
  import sys
  
  # sys.path: python解释器查找包的路径
  sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
  sys.path.insert(0, BASE_DIR)
  
  # 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 = '79@+w9!(ft_q*=%0ilvacg5hgwon=-b)$*cx6x$6_1ss-!h^y^'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = True
  
  # 增加可以访问后端的域名
  ALLOWED_HOSTS = [
      'api.meiduo.site',
      '127.0.0.1',
      'localhost',
      'www.meiduo.site'
  ]
  
  # Application definition
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'users.apps.UsersConfig',
      'verifications.apps.VerificationsConfig',
      'oauth.apps.OauthConfig',
      'areas.apps.AreasConfig',
      'goods.apps.GoodsConfig',
      'contents.apps.ContentsConfig',
      'carts.apps.CartsConfig',
      'orders.apps.OrdersConfig',
      'payments.apps.PaymentsConfig',
  
      'rest_framework',
      'corsheaders',  # 使用CORS来解决后端对跨域访问的支持
      'ckeditor',  # 富文本编辑器
      'ckeditor_uploader',  # 富文本编辑器上传图片模块
      'django_crontab',  # 定时任务
      'haystack',  # 模块化的搜索
      'xadmin',
      'crispy_forms',
      'reversion',
  ]
  
  MIDDLEWARE = [
      'corsheaders.middleware.CorsMiddleware',
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  ]
  
  ROOT_URLCONF = 'ManyBeautifulMall.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 = 'ManyBeautifulMall.wsgi.application'
  
  # Database
  # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.mysql',
          'HOST': '127.0.0.1',  # 数据库主机
          'PORT': 3306,  # 数据库端口
          'USER': 'meiduo',  # 数据库用户名
          'PASSWORD': 'meiduo',  # 数据库用户密码
          'NAME': 'md_mall'  # 数据库名字
      }
  }
  
  # 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 = 'zh-hans'
  
  TIME_ZONE = 'Asia/Shanghai'
  
  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/'
  
  # 配置缓存
  CACHES = {
      #  配置缓存，必须要有default
      "default": {
          "BACKEND": "django_redis.cache.RedisCache",
          "LOCATION": "redis://127.0.0.1:6379/0",
          "OPTIONS": {
              "CLIENT_CLASS": "django_redis.client.DefaultClient",
          }
      },
      "session": {
          "BACKEND": "django_redis.cache.RedisCache",
          "LOCATION": "redis://127.0.0.1:6379/1",
          "OPTIONS": {
              "CLIENT_CLASS": "django_redis.client.DefaultClient",
          }
      },
      "sms_code": {  # 短信验证码
          "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",
          }
      },
      "cart": {  # 购物车信息保存
          "BACKEND": "django_redis.cache.RedisCache",
          "LOCATION": "redis://127.0.0.1:6379/4",
          "OPTIONS": {
              "CLIENT_CLASS": "django_redis.client.DefaultClient",
          }
      },
  }
  # 设置session的保存方案
  # 指定session使用缓存进行保存,缓存保存在redis中
  SESSION_ENGINE = "django.contrib.sessions.backends.cache"
  SESSION_CACHE_ALIAS = "session"
  
  # 添加日志
  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': {  # 向终端中输出日志  在debug模试下
              'level': 'INFO',
              'filters': ['require_debug_true'],
              'class': 'logging.StreamHandler',
              'formatter': 'simple'
          },
          'file': {  # 向文件中输出日志
              'level': 'INFO',
              'class': 'logging.handlers.RotatingFileHandler',
              'filename': os.path.join(BASE_DIR, "../logs/meiduo.log"),  # 日志文件的位置
              'maxBytes': 300 * 1024 * 1024,
              'backupCount': 10,
              'formatter': 'verbose'
          },
      },
      'loggers': {  # 日志器
          'django': {  # 定义了一个名为django的日志器
              'handlers': ['console', 'file'],  # 可以同时向终端与文件中输出日志
              'propagate': True,  # 是否继续传递日志信息
              'level': 'INFO',  # 日志器接收的最低日志级别
          },
      }
  }
  
  REST_FRAMEWORK = {
      # 异常处理
      'EXCEPTION_HANDLER': 'utils.exceptions.exception_handler',
      # 身份认证
      'DEFAULT_AUTHENTICATION_CLASSES': (
          # 前后段分离使用jwt
          'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
          # 访问admin后台时使用session
          'rest_framework.authentication.SessionAuthentication',
          'rest_framework.authentication.BasicAuthentication',
      ),
      # 分页
      'DEFAULT_PAGINATION_CLASS': 'utils.pagination.SKUListPagination',
  }
  
  # 设置缓存数据保存位置和有效期
  REST_FRAMEWORK_EXTENSIONS = {
      # 缓存时间
      'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60 * 60,
      # 缓存存储
      'DEFAULT_USE_CACHE': 'default',
  }
  
  JWT_AUTH = {
      # 指明token的有效期
      'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
      # 指定返回类型
      'JWT_RESPONSE_PAYLOAD_HANDLER': 'users.utils.jwt_response_payload_handler',
  }
  
  # 使django的认证系统使用我们自定义的模型类
  # 应用名.模型类名
  # 设置之后,进行数据库迁移
  AUTH_USER_MODEL = "users.User"
  
  # 添加白名单  写鬣域名可以访问`后端接口
  CORS_ORIGIN_WHITELIST = (
      'www.meiduo.site:8080',
  )
  CORS_ALLOW_CREDENTIALS = True  # 允许携带cookie
  
  # 自定义认证后端,用于登陆时的认证
  AUTHENTICATION_BACKENDS = [
      'users.utils.UsernameMobileAuthBackend',
  ]
  
  # QQ登陆参数
  # 申请QQ登录成功后，分配给应用的appid。
  QQ_CLIENT_ID = '101474184'
  # 申请QQ登录成功后，分配给网站的appkey
  QQ_CLIENT_SECRET = 'c6ce949e04e12ecc909ae6a8b09b637c'
  # 成功授权后的回调地址，必须是注册appid时填写的主域名下的地址
  QQ_REDIRECT_URI = 'http://www.meiduo.site:8080/oauth_callback.html'
  QQ_STATE = '/'
  
  # 设置邮箱的配置信息
  EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  EMAIL_HOST = 'smtp.qq.com'
  EMAIL_PORT = 25
  EMAIL_HOST_USER = '627001516@qq.com'  # 发送邮件的邮箱
  EMAIL_HOST_PASSWORD = 'fdinztozrdtpbajd'  # 在邮箱中设置的客户端授权密码
  EMAIL_FROM = '略略略略略略<627001516@qq.com>'  # 收件人看到的发件人
  
  # django文件存储
  DEFAULT_FILE_STORAGE = 'utils.fastdfs.fdfs_storage.FastDFSStorage'
  
  # 指定FastDFS的地址,配置文件
  FDFS_URL = 'http://image.meiduo.site:8888/'
  FDFS_CLIENT_CONF = os.path.join(BASE_DIR, 'utils/fastdfs/client.conf')
  
  # ckeditor设置
  CKEDITOR_CONFIGS = {
      'default': {
          'toolbar': 'full',  # 工具条功能
          'height': 300,  # 编辑器高度
          # 'width': 300,  # 编辑器宽度
      },
  }
  CKEDITOR_UPLOAD_PATH = ''  # 上传图片保存路径，使用了FastDFS，所以此处设为''
  
  # 生成的静态html文件保存目录
  GENERATED_STATIC_HTML_FILES_DIR = os.path.join(os.path.dirname(os.path.dirname(BASE_DIR)), 'front_end_pc')
  
  # 定时任务
  CRONJOBS_URL = os.path.join(os.path.dirname(BASE_DIR), 'logs/crontab.log')
  CRONJOBS = [
      # 每1分钟执行一次生成主页静态文件
      ('*/1 * * * *', 'contents.crons.generate_index_html', '>> ' + CRONJOBS_URL),
  ]
  # 解决crontab中文问题
  CRONTAB_COMMAND_PREFIX = 'LANG_ALL=zh_cn.UTF-8'
  
  # 配置Haystack搜索引擎后端
  HAYSTACK_CONNECTIONS = {
      'default': {
          'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
          # 端口号固定为9200
          'URL': 'http://192.168.188.136:9200/',
          # 指定elasticsearch建立的索引库的名称
          'INDEX_NAME': 'md_mall',
      },
  }
  # 当添加、修改、删除数据时，自动生成索引  es自动重建索引
  # 保证了在Django运行起来后，有新的数据产生时，haystack仍然可以让Elasticsearch实时生成新数据的索引
  HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
  
  # 支付宝
  ALIPAY_APPID = "2016092000555904"
  ALIPAY_URL = "https://openapi.alipaydev.com/gateway.do"
  ALIPAY_DEBUG = True
  ALIPAY_PRIVATE_KEY_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                                         "apps/payments/keys/app_private_key.pem")
  ALIPAY_PUBLIC_KEY_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                                        "apps/payments/keys/alipay_public_key.pem")
  ALIPAY_RETURN_URL = "http://www.meiduo.site:8080/pay_success.html"
  