内容简介:flask设置配置的的方式有三种方法一:直接在代码中使用app.config[‘配置名’] 的方式app.debug = True 等价于 app.config[‘debug’] = True,但是只要少部分参数支持app.debug = True的方式
flask设置配置的的方式有三种
方法一:直接在代码中使用app.config[‘配置名’] 的方式
app.debug = True 等价于 app.config[‘debug’] = True,但是只要少部分参数支持app.debug = True的方式
from flask import Flask
app = Flask(__name__)
# flask 配置文件
app.debug = True
# app.config['debug'] = True
app.secret_key = "password"
# app.config['secret_key'] = "password"
@app.route('/')
def index():
return 'Hellow World!'
if __name__ == '__main__':
app.run(
方法二:使用 app.config.from_pyfile(“python文件名称”) 读取一个py文件的方式导入
创建一个settings.py 文件内容如下,配置文件的变量名都必须是大写的
DEBUG = True
再调用代码中输入如下
app.config.from_pyfile("settings.py")
方式三:app.config.from_object(“python类或类的路径”)
创建一个 settings.py文件,内容如下
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
在代码中导入settings.py 文件
app.config.from_object("settings.ProductionConfig")
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Definitive Guide to MongoDB
Peter Membrey、Wouter Thielen / Apress / 2010-08-26 / USD 44.99
MongoDB, a cross-platform NoSQL database, is the fastest-growing new database in the world. MongoDB provides a rich document orientated structure with dynamic queries that you’ll recognize from RDMBS ......一起来看看 《The Definitive Guide to MongoDB》 这本书的介绍吧!