Files

245 lines
6.9 KiB
Python

"""
@author: Lambert
@time: 2020/06/02 14:04
@file: settings.py
@contact: l156486648@163.com
@site: blog.25years.xyz
"""
"""
Django settings for blog project.
Generated by 'django-admin startproject' using Django 3.0.6.
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
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&zg_^1xr97)+$mvved7)ndncb1pm9kp0%!31@+f^5)f^am=$vj'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
AUTHENTICATION_BACKENDS = (
'user.views.CustomBackend',
)
# 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',
'rest_framework',
'haystack',
'mptt',
'user',
'article',
'jqueryDemo',
'notebook',
'filemanagement'
# 'debug_toolbar',
]
MIDDLEWARE = [
# 将数据更新到缓存中
# 'django.middleware.cache.UpdateCacheMiddleware',
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
# 'django.middleware.gzip.GZipMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
# 从缓存中读取数据
# 'django.middleware.cache.FetchFromCacheMiddleware',
]
# UpdateCacheMiddleware必须是第一个中间件,
# 原因为:因为避免之前的中间件修改过response的内容,造成缓存和数据库内容不一致
# FetchFromCacheMiddleware必须是最后一个中间件
# 原因为:因为 要先请求进来,要先经过CSRF中间件,因为不合法的request,缓存也不应该给让他看到
# CACHE_MIDDLEWARE_ALIAS = "25years"
CACHE_MIDDLEWARE_SECONDS = 60 * 60
CACHE_MIDDLEWARE_KEY_PREFIX = "blog"
INTERNAL_IPS = [
# ...
'127.0.0.1',
# ...
]
ROOT_URLCONF = 'blog.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.template.context_processors.media', # 解决template 里面{{ MEDIA_URL }}无法使用,配置后,会自动往前端添加MEDIA_URL标签.
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'blog.wsgi.application'
AUTH_USER_MODEL = 'user.UserProfile'
X_FRAME_OPTIONS = 'SAMEORIGIN'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
# 数据库自行配置
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'xxxxx',
'PORT': 'xxxx',
'USER': 'xxxx',
'PASSWORD': 'xxxx',
'NAME': 'DjangoBlog',
# 避免映射数据库时出现警告
'OPTIONS': {
'init_command': "SET sql_mode='traditional'",
'charset': 'utf8mb4',
},
}
}
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://xxxx",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"PASSWORD": "xxxx",
"CONNECTION_POOL_KWARGS": {"max_connections": 100},
# "CONNECTION_POOL_KWARGS": {"max_connections": 100, "decode_responses": True},
# 'CONNECTION_POOL_KWARGS': {}, # 添加这一行,解决 格式总是为bytes 问题
}
}
}
# 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 = '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/'
STATIC_ROOT = os.path.join(BASE_DIR, 'collectstatic')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # media即为图片上传的根路径
AUTH_USER_MODEL = 'user.UserProfile'
EMAIL_HOST = "smtp.163.com" #smtp 服务器域名
EMAIL_PORT = 25
EMAIL_HOST_USER = "l156486648@163.com" #用户名
EMAIL_HOST_PASSWORD = "xxxxx"
EMAIL_USE_TLS= False
EMAIL_FROM = "l156486648@163.com"
DEFAULT_FROM_EMAIL = "l156486648@163.com"
# LOG_DIR = os.path.join(BASE_DIR, "log")
# log_file_path = os.path.join(LOG_DIR, "debug.log")
#
#
# if not os.path.exists(LOG_DIR):
# os.mkdir(LOG_DIR)
#
# if not os.path.exists(log_file_path):
# fp = open(log_file_path,'a')
# fp.close()
LOGIN_URL = '/user/login/' # 这个路径需要根据你网站的实际登陆地址来设置
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
}
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
# 'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.IsAuthenticated'
# ],
'DEFAULT_AUTHENTICATION_CLASSES': [
# 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
],
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}