# coding:utf-8
"""
Django settings for firstdjango project.

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

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

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

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# __file__可以获取到当前文件（包含这个代码的文件）
# os.path.dirname(__file__)得到文件爱你所在目录，在一次就是目录上一级，
# BASE_DIR为项目所在目录，
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')=hvbmj*xt6q8k&=wf1h=8s2^o*q#6smvu#!nq-n6+j2@oj^3g'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# DEBUG=TURE如果出现BUG便于看见问题，部署项目时最好不让用户看见BUG
ALLOWED_HOSTS = []
# ALLOWED_HOSTS 允许你设置那些域名可以访问
# ALLOWED_HOSTS = ['*.besttome.com','www.lalala.com']
# 当 DEBUG=False 时，这个为必填项
# 如果不想输入，可以用 ALLOW_HOSTS = ['*'] 来允许所有的。
# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'django.contrib.redirects',

    'learn', 'blog', 'tools', 'users',
    # 'south',
]
# AUTH_USER_MODEL = 'tool.User'
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',
]

ROOT_URLCONF = 'firstdjango.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates').replace('\\', '/'), ],
        '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 = 'firstdjango.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'python',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'OPTIONS': {
            'autocommit': True,
        }
    },
    'db1': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'food',
        'USER': 'root',
        'PASSWORD': '123456',
        "HOST": "localhost",
    },
    'db2': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'learn',
        'USER': 'root',
        'PASSWORD': '123456',
        "HOST": "localhost",
    },
}
DATABASE_ROUTERS = ['database_router.database_router.DatabaseAppsRouter']
# Databasedatabase_router.DatabaseAppsRouter
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASE_APPS_MAPPING = {
    # example:
    # 'app_name':'database_name',
    'tools': 'db1',
    'learn': 'db2',
}
# SOUTH_DATABASE_ADAPTERS = {
#     'default': 'south.db.mysql'
# }
# Password validation
# https://docs.djangoproject.com/en/dev/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',
    },
]

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:8000',
    }
}
# python manage.py createcachetable
# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/

LANGUAGE_CODE = 'zh-Hans'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

STATIC_URL = '/static/'
# static是静态文件所在目录 js css
# 部署时python manage.py collectstatic 可以把静态文件收集到（复制到）STATIC_ROOT
# 共用的静态文件，可以设置STATICFILES_DIRS
# STATICFILES_DIRS = (
#     os.path.join(BASE_DIR, "common_static"),
#     '/var/www/static/',
# )
# MEDIA_URL = '/media/'
# MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# media文件夹用来存放用户上传的文件，与权限有关
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'common_static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# 指定所有 app 共用的静态文件
# python manage.py collectstatic
# 这一句话就会把以前放在app下static中的静态文件全部拷贝到
# settings.py 中设置的 STATIC_ROOT 文件夹中
