193 lines
5.3 KiB
Python
193 lines
5.3 KiB
Python
"""
|
|
Django settings for myblog project.
|
|
|
|
Generated by 'django-admin startproject' using Django 5.2.4.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/5.2/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/5.2/ref/settings/
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
DATA_DIR = BASE_DIR / 'data'
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
# 生产环境请在 local_settings.py 中覆盖
|
|
SECRET_KEY = 'django-insecure-g224%sp()h))26kj26pnnfoayu-knah+!)h9uzgqeece&6*clp'
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
# 生产环境请在 local_settings.py 中设置为 False
|
|
DEBUG = True
|
|
|
|
# 生产环境请在 local_settings.py 中配置
|
|
ALLOWED_HOSTS = []
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'blog',
|
|
'mdeditor',
|
|
]
|
|
|
|
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 = 'config.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'config.wsgi.application'
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': BASE_DIR / 'db.sqlite3',
|
|
}
|
|
}
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/5.2/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/5.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'zh-Hans'
|
|
TIME_ZONE = 'Asia/Shanghai'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = DATA_DIR / 'static'
|
|
|
|
MEDIA_URL = '/media/'
|
|
MEDIA_ROOT = DATA_DIR / 'media'
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
CSRF_TRUSTED_ORIGINS = [
|
|
"https://www.yuangyaa.com",
|
|
"http://www.yuangyaa.com",
|
|
"http://yuangyaa.com",
|
|
"https://yuangyaa.com",
|
|
]
|
|
|
|
# 添加 MDEditor 配置
|
|
MDEDITOR_CONFIGS = {
|
|
'default': {
|
|
'width': '100%',
|
|
'height': 700,
|
|
'toolbar': ["undo", "redo", "|",
|
|
"bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|",
|
|
"h1", "h2", "h3", "h5", "h6", "|",
|
|
"list-ul", "list-ol", "hr", "|",
|
|
"link", "reference-link", "image", "code", "preformatted-text", "code-block", "table", "datetime",
|
|
"emoji", "html-entities", "pagebreak", "goto-line", "|", "help", "info",
|
|
"||", "preview", "watch", "fullscreen"],
|
|
'upload_image_formats': ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
|
|
'image_folder': 'editor',
|
|
'theme': 'default',
|
|
'preview_theme': 'default',
|
|
'editor_theme': 'default',
|
|
'toolbar_autofixed': True,
|
|
'search_replace': True,
|
|
'emoji': True,
|
|
'tex': False,
|
|
'language': 'zh',
|
|
'focus': False,
|
|
'auto_height': False,
|
|
}
|
|
}
|
|
|
|
X_FRAME_OPTIONS = 'SAMEORIGIN'
|
|
|
|
LOGGING = {
|
|
'version': 1,
|
|
'disable_existing_loggers': False,
|
|
'formatters': {
|
|
'verbose': {
|
|
'format': '{levelname} {asctime} {module} {message}',
|
|
'style': '{',
|
|
},
|
|
},
|
|
'handlers': {
|
|
'file': {
|
|
'level': 'WARNING',
|
|
'class': 'logging.handlers.RotatingFileHandler',
|
|
'filename': DATA_DIR / 'logs' / 'django.log',
|
|
'maxBytes': 1024 * 1024 * 5,
|
|
'backupCount': 5,
|
|
'formatter': 'verbose',
|
|
},
|
|
},
|
|
'root': {
|
|
'handlers': ['file'],
|
|
'level': 'WARNING',
|
|
},
|
|
}
|
|
|
|
# settings.py 末尾加上这段
|
|
try:
|
|
from .local_settings import *
|
|
except ImportError:
|
|
pass
|