方法一、直接配置
Python代码![](https://i-blog.csdnimg.cn/blog_migrate/17b90e0c4f469a73a755fdc43eff3ec8.png)
app.config['HOST']='xxx.a.com'
print app.config.get('HOST')
方法二、通过环境变量加载配置
export MyAppConfig=/path/to/settings.cfg
Python代码
![](https://i-blog.csdnimg.cn/blog_migrate/17b90e0c4f469a73a755fdc43eff3ec8.png)
app.config.from_envvar('MyAppConfig')
这样将会加载环境变量指向的配置文件,并加载
方法三、通过对象加载
Python代码
![](https://i-blog.csdnimg.cn/blog_migrate/17b90e0c4f469a73a755fdc43eff3ec8.png)
class Config(object):
DEBUG = False
TESTING = False
DATABASE_URI = 'sqlite://:memory:'
class ProductionConfig(Config):
DATABASE_URI = 'mysql://user@localhost/foo'
class DevelopmentConfig(Config):
DEBUG = True
class TestingConfig(Config):
TESTING = True
from flask import Flask
app = Flask(__name__)
app.config.from_object(ProductionConfig)
print app.config.get('DATABASE_URI') # mysql://user@localhost/foo
或者: