【发布时间】:2020-07-17 22:42:58
【问题描述】:
我正在尝试将 Schema 嵌套在另一个 Schema 中,如下所示:
class RecipePaginationSchema(PaginationSchema):
data = fields.Nested(RecipeSchema, attribute = "items", many = True)
结果应该是这样的:
{
"links": {
"first": "http://localhost:5000/users/name/recipes?per_page=2&visibility=all&page=1",
"last": "http://localhost:5000/users/name/recipes?per_page=2&visibility=all&page=2",
"next": "http://localhost:5000/users/name/recipes?per_page=2&visibility=all&page=2"
},
"page": 1,
"pages": 2,
"per_page": 2,
"total": 3,
"data": [
{
"id": 11,
...
}
}
但是,当我尝试使用另一个属性而不是“项目”时,我没有得到 JSON 响应中的“数据”部分。那么,这个属性到底指的是什么?
顺便说一句,我正在关注 Packt 的 Python API 开发基础一书。
【问题讨论】:
-
您提出了一个明确的问题并发布了一个格式化的问题。 +1
标签: python json flask schema marshmallow