【问题标题】:How do I build a complex filter for Flask-Restless when using Requests?使用请求时如何为 Flask-Restless 构建复杂的过滤器?
【发布时间】:2015-10-13 22:32:30
【问题描述】:

我想使用 Requests 对 Flask-Restless api 进行复杂查询。我不确定如何使用 Requests 构建以下 query from the examples。如何进行此查询?

GET /api/person?q={"filters":[{"name":"age","op":"ge","val":10}]} HTTP/1.1
Host: example.com

【问题讨论】:

    标签: python flask python-requests flask-restless


    【解决方案1】:

    Flask-Restless 需要 JSON 格式的查询字符串。给出的示例是一个带有过滤器列表的字典,每个过滤器都是另一个字典。构建您的查询结构,将其转储为 JSON,然后使用 Requests 进行查询。

    import json
    q = {'filters': [{'name': 'age', 'op': 'ge', 'val': 10}]}
    r = requests.get('http://example.com', params={'q': json.dumps(q)})
    

    【讨论】:

      猜你喜欢
      • 2015-10-14
      • 2016-06-18
      • 1970-01-01
      • 2023-04-06
      • 2014-08-02
      • 2015-04-22
      • 2014-08-11
      • 2017-05-14
      • 2016-01-14
      相关资源
      最近更新 更多