15 lines
438 B
Python
15 lines
438 B
Python
|
|
"""公共配置:统一从环境变量或 Flask config 读取配置项。"""
|
|||
|
|
import os
|
|||
|
|
from flask import current_app
|
|||
|
|
|
|||
|
|
|
|||
|
|
def get_config(key: str, default: str = "") -> str:
|
|||
|
|
"""从环境变量获取配置(优先级:环境变量 > Flask config)。"""
|
|||
|
|
value = os.environ.get(key, "")
|
|||
|
|
if value:
|
|||
|
|
return value
|
|||
|
|
try:
|
|||
|
|
return current_app.config.get(key, default)
|
|||
|
|
except RuntimeError:
|
|||
|
|
return default
|