Files
edward/config/env_loader.py
konjacpotato 1e2d739d00
All checks were successful
Gitea Actions Demo / deploy (push) Successful in 26s
task: add real estate story
2026-02-15 15:29:13 +08:00

22 lines
573 B
Python

import os
from dotenv import load_dotenv
def load_env():
"""
自动根据 ENV 加载对应的 .env 文件
"""
base_file = ".env"
prod_file = ".env.prod"
test_file = ".env.test"
# 先加载基础 .env
if os.path.exists(base_file):
load_dotenv(base_file)
# 根据参数 ENV 再加载其他环境
env = os.getenv("ENV", "dev")
if env == "prod" and os.path.exists(prod_file):
load_dotenv(prod_file, override=True)
elif env == "test" and os.path.exists(test_file):
load_dotenv(test_file, override=True)