1. 使用from_object
先创建config.py
import config app = Flask(__name__) app.config.from_object(config)
2. 使用from_pyfile。不需要导入config.py文件,作为参数即可。
文件类型不限制为py,也可以是txt
要保留后缀名称
app = Flask(__name__) app.config.from_pyfile("config.py")
app.config.from_pyfile('settings.py',silent=True)
# silent=True表示如果配置文件不存在的时候不抛出异常,默认是为False,会抛出异常。