
config/dev_config.py
SECRET_KEY = 'some secret words'DEBUG = True
config/prod_config.py
SECRET_KEY = 'some secret words'DEBUG = False
windows下,在“系统设置”——“环境变量”——“用户变量”下,点击“新建” 添加进去
app = Flask(__name__)app.config.from_pyfile('config/pro_config.py')
import osPAAS_V2_ENVIRONMENT = os.environ.get("BK_ENV", "development")ENVIRONMENT = {"development": "dev","testing": "stag","production": "prod",}.get(PAAS_V2_ENVIRONMENT)config_file = "config/{env}_config.py".format(env=ENVIRONMENT)app.config.from_pyfile(config_file)
os.environ.get("xx")解释:os.environ.get("xx") # os.environ是字典。get获得环境变量xx的值os.environ.get("BK_ENV", "development") # 找BK_ENV,如果没有就输出development
from flask import current_app as appprint(app.config["ABC"])