探索Quart框架与微服务开发中的编码、测试和文档
1. 探索Quart框架
1.1 加载配置
Quart通过 app.config 公开其配置,因此从JSON、YAML或其他流行的基于文本的配置格式加载额外选项非常简单。以下是一些等效的示例:
from quart import Quart
import yaml
from pathlib import Path
app = Quart(__name__)
print(Path("prod_settings.json").read_text())
{
"DEBUG": false,
"SQLURI":"postgres://username:xxx@localhost/db"
}
app.config.from_json("prod_settings.json")
app.config["SQLURI"]
'postgres://username:xxx@localhost/db'
print(Path("prod_settings.yml").read_text())
---
DEBUG: False
SQLURI: "postgres://username:xxx@localhost/db"
app.config.from_file("prod_settings.yml", yaml.safe_load)
你可以给 from_file 一个函数来解析数据,如 yaml.safe_load 、 tom
超级会员免费看
订阅专栏 解锁全文
1404

被折叠的 条评论
为什么被折叠?



