处理环境配置位置问题

This commit is contained in:
zk
2026-07-01 16:02:17 +08:00
parent b79bcb932c
commit 547cf21bf2
2 changed files with 11 additions and 3 deletions
+5 -2
View File
@@ -1,10 +1,13 @@
import os
from .settings import Settings
from .settings import BASE_DIR, Settings
_env = os.getenv("ENV", "dev")
_env_files = {"dev": ".env", "test": ".env.test", "pro": ".env.prod"}
settings = Settings(_env_file=_env_files.get(_env, ".env"))
# 使用基于项目根目录的绝对路径,避免受 PyCharm/命令行工作目录(CWD)影响
_env_file = BASE_DIR / _env_files.get(_env, ".env")
settings = Settings(_env_file=_env_file)
__all__ = ["settings"]