URL 查询参数作为金字塔中的字典

URL query parameter as a dictionary in Pyramid

JSON API specification uses a dictionary like syntax for some query parameters:

GET /articles?include=author&fields[articles]=title,body,author&fields[people]=name HTTP/1.1

有什么简单的方法可以使用 Pyramid 检索上述 fields 参数作为字典吗?

为提供更多详细信息,给出了以下 fields 参数:

我想将它们全部放入 Python 字典中:

fields = {
    'articles': 'title,body,author',
    'people': 'name',
}

如果我明白你在问什么,Pyramid Quick Tour 中有一个示例,其中包含指向更多示例和完整金字塔请求的链接 API。

本质上:

fields_articles = request.params.get('fields[articles]', 'No articles provided')
fields_people = request.params.get('fields[people]', 'No people provided')

然后将它们放入字典中。

编辑

这就够了吗?

fields = {
    'articles': request.params.get('fields[articles]', ''),
    'people': request.params.get('fields[people]', ''),
}