如果对app.config是什么还心有疑惑,或者对于这种配置方式很陌生,参考:flask项目配置 app.config
classConfig.py:
class BaseConfig(object):
SECRET_KEY='secret string'
class DevelopmentConfig(BaseConfig):
ENVSTR = 'IN DevelopmentConfig '
class ProductConfig(BaseConfig):
ENVSTR='IN ProductConfig '
config={
'development':DevelopmentConfig,
'production':ProductConfig
}
app.py
from flask import Flask
from demoConfig.classConfig import config
app =Flask(__name__)
config_name='development'
# config_name='production'
app.config.from_object(config[config_name])
print(app.config['ENVSTR'])
运行结果:
IN DevelopmentConfig