25 lines
887 B
Python
25 lines
887 B
Python
import os
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
class Settings:
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "mysql+pymysql://root:password@localhost:3306/tielu_db")
|
|
DB_HOST = os.getenv("DB_HOST", "localhost")
|
|
DB_PORT = int(os.getenv("DB_PORT", 3306))
|
|
DB_USER = os.getenv("DB_USER", "root")
|
|
DB_PASSWORD = os.getenv("DB_PASSWORD", "password")
|
|
DB_NAME = os.getenv("DB_NAME", "tielu_db")
|
|
|
|
APP_HOST = os.getenv("APP_HOST", "0.0.0.0")
|
|
APP_PORT = int(os.getenv("APP_PORT", 8000))
|
|
APP_DEBUG = os.getenv("APP_DEBUG", "True").lower() == "true"
|
|
|
|
settings = Settings()
|
|
|
|
|
|
# 打印配置验证
|
|
print("读取到的数据库配置:")
|
|
print(f"DATABASE_URL: {settings.DATABASE_URL}") # 应显示包含 railway@localhost:3306
|
|
print(f"DB_HOST: {settings.DB_HOST}") # 应显示 localhost
|
|
print(f"DB_USER: {settings.DB_USER}") # 应显示 railway |