码迷,mamicode.com
首页 > 其他好文 > 详细

django settings.py

时间:2019-05-27 13:17:45      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:pre   mysq   oca   com   日志   ase   keep   信息   int   

"""
Django settings for mysite project.

Generated by ‘django-admin startproject‘ using Django 2.1.7.

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

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

import os ,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, BASE_DIR)
sys.path.insert(1, os.path.join(BASE_DIR, ‘apps‘)) # 创建应用之后,把apps目录加入到sys.path中


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ‘hv6rr%=5zm3%79&)f0-er^#78xgi5#=hg_#a4*^o90=ubil(fl‘

# 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‘,
‘news‘,
‘course‘,
‘doc‘,
‘users‘,
‘verifications‘,
‘admin‘,
‘haystack‘, # 引用django的haystack库同 django.contrib.auth等 用于建立索引 eliticsearsh

]

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 = ‘mysite.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‘,
],
# 将函数内置到模板中 https://docs.djangoproject.com/en/2.1/topics/templates/
‘builtins‘: [‘django.templatetags.static‘],
},
},
]

WSGI_APPLICATION = ‘mysite.wsgi.application‘


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

DATABASES = {
‘default‘: {
‘ENGINE‘: ‘django.db.backends.mysql‘,
‘OPTIONS‘: {
‘read_default_file‘: ‘utils/dbs/dbcfg‘,
},
}
}


CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache", # 指定redis缓存后端
"LOCATION": "redis://127.0.0.1:6379/0",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
# "PASSWORD": "mysecret"
}
},
# 同样可以指定多个redis
"session": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
"verify_codes": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/2",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
"sms_codes": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/3",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},

}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators



# 将用户的session保存到redis中
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
# 指定缓存redis的别名
SESSION_CACHE_ALIAS = "session"

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

STATIC_URL = ‘/static/‘
STATICFILES_DIRS = [
os.path.join(BASE_DIR, ‘static‘), # 用于存放静态文件
]

MEDIA_URL = ‘/media/‘
MEDIA_ROOT = os.path.join(BASE_DIR, ‘media‘) # 用于存放图片

# 配置日志器,记录网站的日志信息
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.utils.log.RequireDebugTrue‘,
},
},
‘handlers‘: {
‘console‘: {
‘level‘: ‘DEBUG‘,
‘filters‘: [‘require_debug_true‘],
‘class‘: ‘logging.StreamHandler‘,
‘formatter‘: ‘simple‘
},
‘file‘: {
‘level‘: ‘INFO‘,
‘class‘: ‘logging.handlers.RotatingFileHandler‘,
‘filename‘: os.path.join(BASE_DIR, "logs/mysite.log"), # 日志文件的位置
‘maxBytes‘: 300 * 1024 * 1024,
‘backupCount‘: 10,
‘formatter‘: ‘verbose‘
},
},
‘loggers‘: {
‘django‘: { # 定义了一个名为django的日志器 可以定义多个日志器
‘handlers‘: [‘console‘, ‘file‘],
‘propagate‘: True,
‘level‘: ‘INFO‘, # 日志器接收的最低日志级别
},
}
}

# 自定义用户模型
AUTH_USER_MODEL = ‘users.Users‘ # usersAPP下的User模型 ,默认是django的authen

ELASTICSEARCH_DSL = { # 连接服务sevice
‘default‘: {
‘hosts‘: ‘127.0.0.1:8002‘
},
}

# Haystack
HAYSTACK_CONNECTIONS = { # 配置具体信息 引擎,URL 在浏览器中访问时用.
‘default‘: {
‘ENGINE‘: ‘haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine‘,
‘URL‘: ‘http://127.0.0.1:8002/‘, # 此处为elasticsearch运行的服务器ip地址,端口号默认为9200
‘INDEX_NAME‘: ‘mystie_news‘, # 指定elasticsearch建立的索引库的名称 自定义
},
}

# 设置每页显示的数据量
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 5
# 索引的配置:当数据库改变时,会自动更新索引
HAYSTACK_SIGNAL_PROCESSOR = ‘haystack.signals.RealtimeSignalProcessor‘
# 站点域名和端口配置 用于路径拼接
SITE_DOMAIN_PORT = "http://192.168.1.11:8000/"

django settings.py

标签:pre   mysq   oca   com   日志   ase   keep   信息   int   

原文地址:https://www.cnblogs.com/crave/p/10929911.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!