"""
Django settings for DjangoLearn project.

Generated by 'django-admin startproject' using Django 3.0.4.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# 工程项目路径: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print("工程的总路径-------:",BASE_DIR)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# 加签: keep the secret key used in production secret!
SECRET_KEY = 'fn_*(&cv)nww^*=g%_%g8hwh$pe@rp+_r!y#$scjmjh++)47z8'

# 调试模式: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []

#生产环境 发布环境
# DEBUG = False
# ALLOWED_HOSTS = []


# Application definition

# 注册应用
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'auser.apps.AuserConfig',
    'brouter.apps.BrouterConfig',
    'brequest.apps.BrequestConfig',
    'cresponse.apps.CresponseConfig',
    'dcookie.apps.DcookieConfig',
    'ereview.apps.EreviewConfig',
    'aclassview.apps.AclassviewConfig',
    'btemplates.apps.BtemplatesConfig',
    'adbs.apps.AdbsConfig',
]

# 中间件
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    #使用postman 发送除了GET 请求方式之外 其他的 都注释
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

    #注册中间件
    'middleware.simple_middleware',
    'middleware.simple_middleware_two',

]
# django项目入口 第一个路由配置  ROOT_URLCONF
ROOT_URLCONF = 'DjangoLearn.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',
            ],
        },
    },
]

# jinja2模板配置
# TEMPLATES = [
#     {
#         'BACKEND': 'django.template.backends.jinja2.Jinja2',#修改1
#         'DIRS': [os.path.join(BASE_DIR, 'templates')],
#         'APP_DIRS':True,
#         'OPTIONS':{
#             'environment': 'jinja2_env.environment',# 修改2
#             '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 = 'DjangoLearn.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

# 数据库的配置
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST':'127.0.0.1',
        'PORT':'3306',
        'USER':'root',
        'PASSWORD':'Yao199612',
        'NAME':'django_demo',

    }
}


# Password validation
# https://docs.djangoproject.com/en/3.0/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/3.0/topics/i18n/

# 本地化
# LANGUAGE_CODE = 'en-us'
# # 时区
# TIME_ZONE = 'UTC'

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/3.0/howto/static-files/

#静态文件的路由
STATIC_URL = '/static/'
# 静态文件夹的路径 STATICFILES_DIRS必须写这个
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static_files')]


# 配置 将session  存储到redis数据库中

CACHES = {
    "default":{
        "BACKEND":'django_redis.cache.RedisCache',
        "LOCATION":"redis://127.0.0.1:6379/1",
        "OPTIONS":{
            "CLIENT_CLASS":"django_redis.client.DefaultClient",
        }
    }
}
# SESSION_ENGINE
SESSION_ENGINE = "django.contrib.sessions.backends.cache"

SESSION_CACHE_ALIAS = "default"

# 配置上传文件的位置
MEDIA_ROOT=os.path.join(BASE_DIR,"media")


