【问题标题】:search_params empty in a PATCH_MANY preprocessor in flask-restless在flask-restless的PATCH_MANY预处理器中search_params为空
【发布时间】:2014-08-10 06:21:00
【问题描述】:

我通过PUT 发出了以下 HTTP 请求:

http://example.com/api/student?q=%7B%22filters%22:%5B%7B%22name%22:%22id%22,%22op%22:%22%3D%3D%22,%22val%22:1%7D%5D,%22disjunction%22:true%7D

查询字符串解码到的位置:

q:{"filters":[{"name":"id","op":"==","val":1}],"disjunction":true}

在我的 flask-restless 代码中,我使用以下选项创建端点:

    {
        'model': Student,
        'methods': ['GET', 'PUT', 'PATCH', 'POST', 'DELETE'],
        'preprocessors': {
            'POST': [pre_post_student],
            'PATCH_MANY': [pre_patch_many_student]
        },
        'allow_patch_many': True
    },

然后我定义了一个预处理器函数:

def pre_patch_many_student(search_params=None, data=None, **kw):
    # Handle group management for the given students

    print search_params

但是,当针对上述请求调用该函数时,search_params 会显示为空字典。

为什么?

【问题讨论】:

    标签: python flask-restless


    【解决方案1】:

    修补时,flask-restless 不会在 url 中查找参数,而是将其作为请求正文的一部分。 因此身体应该是:

    {"q":{<filters and rules>},"field_to_edit":"content",...}
    

    这可能已经太晚了,但无论如何。

    【讨论】:

      猜你喜欢
      • 2013-12-26
      • 2015-06-11
      • 2015-09-09
      • 2013-10-16
      • 2023-03-13
      • 2015-10-14
      • 2014-04-24
      • 1970-01-01
      • 2016-01-14
      相关资源
      最近更新 更多