"""
Django settings for MyDjango project.

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

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

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

import os
import sys

# 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"))
sys.path.insert(0, os.path.join(BASE_DIR, "extra_apps"))

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'u33t%c7#w11ouy(f5&&d6pg2@el^1r6tsb_89)&rhtec1994=('

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',# 管理站点
    'django.contrib.auth',# 认证系统
    'django.contrib.contenttypes',# 用于内容类型的框架
    'django.contrib.sessions',# 会话框架
    'django.contrib.messages',# 消息框架
    'django.contrib.staticfiles',# 管理静态文件框架
    'xiaoyu',# 应用app
    'xadmin',     #新添加xadmin app
    'crispy_forms',#新添加xadmin app
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',# session 中间件
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',#auth中间件
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'MyDjango.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 = 'MyDjango.wsgi.application'


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

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#     }
# }

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'djangotest',
        'HOST': '123.56.231.107',
        'USER': 'root',
        'PASSWORD': '123456',
        'PORT': '3309'
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.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',
    },
]
# 不会检测用户的活跃状态
#在 settings.py 文件里加上下面的配置authenticate就不会检测用户的活跃状态
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.AllowAllUsersModelBackend']

# Internationalization
# https://docs.djangoproject.com/en/2.0/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
USE_TZ = False

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")


# session 设置
SESSION_COOKIE_NAME = "key"                # session的cookie保存在浏览器上是的key
SESSION_COOKIE_PATH = "/"                  # session的cookie保存路径（默认）
SESSION_COOKIE_DOMAIN = None               # session的cookie保存域名（默认）
SESSION_COOKIE_SECURE =False               # 是否Https传输cookie（默认）
SESSION_COOKIE_HTTPONLY = True             # 是否session的cookie只支持http传输（默认）
SESSION_COOKIE_AGE = 1209600               # session的cookie失效日期（2周）（数字为秒数）（默认）
SESSION_EXPIRE_AT_BROWSER_CLOSE = True     # 是否关闭浏览器使得session过期（默认）
SESSION_SAVE_EVERY_REQUEST = True          # 是否每次请求都保存session，默认修改之后才保存（默认）



