Python Eve包含过滤器 [英] Python Eve contains filter

查看:50
本文介绍了Python Eve包含过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以返回字段包含某些值的项目?例如

There's some way to return items that field contains some value? Eg.

获取/people?contains ="foo"

返回名称中带有"foo"一词的所有人.

Return all persons that have the word 'foo' in the name.

预先感谢

推荐答案

您可以使用mongodb $ regex 运算符,该运算符在Eve中默认列入黑名单( MONGO_QUERY_BLACKLIST = ['$ where','$ regex'] ).

You could use mongodb $regex operator, which is blacklisted by default in Eve (MONGO_QUERY_BLACKLIST = ['$where', '$regex']).

MONGO_QUERY_BLACKLIST = ['$ where'] 添加到您的 settings.py 中.然后,您可以像这样查询您的API:

Add MONGO_QUERY_BLACKLIST = ['$where'] to your settings.py. Then you can query your API like this:

?where = {"name":{"$ regex":.* foo.*"}} .

但是要小心.如果您不控制客户端,则启用正则表达式可能会增加您的API漏洞.

Be careful however. If you don't control the client, enabling regexes could potentially increase your API vulnerability.

这篇关于Python Eve包含过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆