首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >[Python EVE]:读取Python EVE中的请求参数值

[Python EVE]:读取Python EVE中的请求参数值
EN

Stack Overflow用户
提问于 2015-04-16 22:50:14
回答 1查看 1.4K关注 0票数 2

我正在开发一个使用python eve的web应用程序。我暴露了几个端点。我有一个名为persons的端点,在数据库模式userid中有一个字段。我希望使用读取请求参数后生成的随机字符串填充该字段。

我的问题是如何读取这些参数。我在Eve文档中找不到相同的语法。

在这方面的任何帮助都是有帮助的。

EN

回答 1

Stack Overflow用户

发布于 2015-04-16 23:26:23

我想像这样的东西会起作用的:

代码语言:javascript
复制
from eve import Eve
from flask import request

def update_inbound_docs(items):
    # retrieve request parameter, if present
    my_arg = request.args.get('key') 
    for document in items:
        # update document 'userid' field according to my_arg
        # value. replace with custom logic.
        document['userid'] = 'bingo' if my_arg else 'ack!'

app = Eve()

# bind your callback to the POST method for 'persons'
# endpoint. it will be invoked after a POST request 
# has been validated and before db is updated, so any 
# update to 'items' will be persisted.
app.on_insert_persons += update_inbound_docs

app.run()

Eve是一个Flask应用程序,因此您可以随意使用Flask request对象。详情请参见Database Hooks

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29678363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档