diff --git a/config/local_settings.example.py b/config/local_settings.example.py index 49edb46..428221b 100644 --- a/config/local_settings.example.py +++ b/config/local_settings.example.py @@ -1,18 +1,30 @@ """ -本地设置示例文件 +生产环境本地设置 使用方法:复制为 local_settings.py 并按需修改 cp local_settings.example.py local_settings.py + +此文件已在 .gitignore 中忽略,不会提交到仓库。 +在此文件中覆盖 settings.py 中的任意配置。 """ -# 生产环境请设置 -# import os -# SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'your-secret-key') +# ============ 安全配置 ============ +# 生成方式: python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())" +SECRET_KEY = 'your-production-secret-key-here' -# DEBUG = False +DEBUG = False -# ALLOWED_HOSTS = ['www.yuangyaa.com', 'yuangyaa.com'] +ALLOWED_HOSTS = ['www.yuangyaa.com', 'yuangyaa.com'] -# 生产环境数据库(PostgreSQL) +# ============ 数据库配置 ============ +# SQLite(轻量级,适合小规模站点) +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': BASE_DIR / 'db.sqlite3', +# } +# } + +# PostgreSQL(推荐生产环境) # DATABASES = { # 'default': { # 'ENGINE': 'django.db.backends.postgresql', diff --git a/config/settings.py b/config/settings.py index 6a7143e..d045f20 100644 --- a/config/settings.py +++ b/config/settings.py @@ -11,7 +11,6 @@ https://docs.djangoproject.com/en/5.2/ref/settings/ """ from pathlib import Path -import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -21,14 +20,14 @@ DATA_DIR = BASE_DIR / 'data' # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.environ.get( - 'DJANGO_SECRET_KEY', - 'django-insecure-g224%sp()h))26kj26pnnfoayu-knah+!)h9uzgqeece&6*clp' -) +# 生产环境请在 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