如何在Falcon Python中使用查询字符串

wos*_*oss 4 python query-string falconframework

您如何将应用程序配置为具有以下功能:

  1. 将api端点定义为 app.add_route('/v1/tablets', TabletsCollection())

  2. 而且仍然可以像这样使用QueryParams https://example.com/api/v1/tablets?limit=12&offset=50&q=tablet name

集合有两种方法on_get来检索整个列表并使用过滤器和on_post创建单个记录。

我已经在网上搜索了一段时间,如何获得query_string和正确解析的参数?

Max*_*ner 5

猎鹰传递给您的API端点的Request对象上都可以使用查询字符串和已解析的查询字符串(作为字典)。

您的处理程序可以执行以下操作:

class TabletsCollection():
    def on_post(self, req, resp):
        print req.query_string
        for key, value in req.params.items():
            print key, value
Run Code Online (Sandbox Code Playgroud)

请参阅http://falcon.readthedocs.io/en/stable/api/request_and_response.html#Request.query_stringhttp://falcon.readthedocs.io/en/stable/api/request_and_response.html#Request.params