Eve框架:修改查询字符串

2024-10-03 17:17:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用pythoneve框架编写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) 我希望,有更好的方法来扩展它。在

有什么想法?在


Tags: 框架api编码getstringonrequestmore
1条回答
网友
1楼 · 发布于 2024-10-03 17:17:00

您应该能够通过处理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()

相关问题 更多 >