我正在使用Python EVE框架编写API。在我的on_post_GET钩子中,出于某种原因,我想用一些额外的条件来扩展request.query_string。
这个request.query_string看起来像一个原始的编码字符串,向现有的字符串中添加一些新的条件是没有用的。
我的字符串看起来像这样:
embedded=%7B%22some_key%22%3A1%2C%22another_key%22%3A1%2C%22one_more_key%22%3A1%2C%22and_more_key%22%3A1%2C%22and_more%22%3A1%2C%22some_specific_key%22%3A1%2C%22the_last_key%22%3A1%7D&where=%7B%22some_statement%22%3A%22in%28%5B%5C%22value1%5C%22%2C%5C%22value2%5C%22%5D%29%22%7D&max_results=10&page=1&sort=%5B%28%22date%22%2C0%29%5D
因此,我想在WHERE语句中添加一个额外的条件。我可能会以某种方式解析它,但有几件事:
1)我可能有另一个条件,与条件相关的硬编码对我来说看起来很糟糕。2)我希望有更好的方式来扩展它。
有什么想法?
发布于 2017-05-09 01:46:54
您应该能够通过处理pre_GET事件挂钩中的lookup来创建过滤器,如pyeve的documentation中的示例所示
def pre_GET(resource, request, lookup):
# only return documents that have a 'username' field.
lookup["username"] = {'$exists': True}
app = Eve()
app.on_pre_GET += pre_GET
app.run()https://stackoverflow.com/questions/43853779
复制相似问题