返回主题:Python Web API 框架实践

知识卡片

普通读书笔记卡 · 3493.e

查询参数按位置绑定模式

理解等级:中级

查询参数也可由载荷模式声明类型与可选性,再把模式绑定到端点的 query 位置,框架便能从 URL 读取、转换并交给处理函数。过滤时仍需区分未传与假值,例如布尔 false 不能用真假判断当成缺失。参见 [[None区别未传与假值]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 6 章《Building REST APIs with Python》(源文件:_epub-src/OEBPS/Text/06.htm) - 结论依据:原文先以 marshmallow 模型声明 `progress`、`limit`、`since`,随后以 `arguments()` 的 `location='query'` 将其绑定到 URL 查询参数,并用 `is not None` 检查是否传入。 - 原始内容:We register the schema for URL query parameters using the blueprint’s arguments() decorator . We specify that the properties defined in the schema are expected in the URL, so we set the location parameter to query .