知识卡片
查询参数按位置绑定模式
查询参数也可由载荷模式声明类型与可选性,再把模式绑定到端点的 query 位置,框架便能从 URL 读取、转换并交给处理函数。过滤时仍需区分未传与假值,例如布尔 false 不能用真假判断当成缺失。参见 [[None区别未传与假值]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《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 .