我通过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
出现为空字典。
为什么?
打补丁时,flask-restless不会在url中查找参数,而是在请求体中查找参数。因此body应该是:
{"q":{<filters and rules>},"field_to_edit":"content",...}
这可能已经太晚了,但无论如何。