【发布时间】:2021-02-18 15:31:14
【问题描述】:
我的架构:
class ArticleBase(Schema):
page: Optional[int] = 1
topic: Optional[List[str]] = Query(None)
路由器:
@api.get("/articles/", tags = ['Articles'])
def article_list(request, article: ArticleBase = Query(...)):
return article
我希望 Pydantic/FastAPI 接受单个值和多个值的查询。
我希望他们都被接受:
www.example.com/articles/?topic=hello&topic=world
www.example.com/articles/?topic=hello
我怎样才能实现它?
我收到的错误消息:
"msg": "value is not a valid list",
"type": "type_error.list"
【问题讨论】:
-
不太确定这个但我会尝试将
topic的默认值设置为None而不是Query(None)。 -
@igotinfected,感谢您的评论。它没有用。有趣的是,编写值列表也不会被接受。