更新: 使用环境变量配置数据库连接

This commit is contained in:
晓丰 2025-04-13 20:08:58 +08:00
parent fcaaf67795
commit 209f18cd63

View File

@ -9,9 +9,13 @@ https://docs.djangoproject.com/en/5.0/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/ https://docs.djangoproject.com/en/5.0/ref/settings/
""" """
import environ
import os
from pathlib import Path from pathlib import Path
env = environ.Env()
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
@ -85,18 +89,17 @@ WSGI_APPLICATION = 'core.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'django.db.backends.mysql',
'NAME': 'tsreshub_db', 'NAME': env('DB_NAME'),
'USER': 'tsreshub_prod', 'USER': env('DB_USER'),
'PASSWORD': 'Tr5h$Prod!92@TsRH', 'PASSWORD': env('DB_PASSWORD'),
'HOST': '39.101.135.56', 'HOST': env('DB_HOST'),
'PORT': '3306', 'PORT': env('DB_PORT'),
'OPTIONS': { 'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
} }
} }
} }
# Password validation # Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators