gpt4 book ai didi

python - bottle request.forms.get 返回 None

转载 作者:太空狗 更新时间:2023-10-30 02:43:00 24 4
gpt4 key购买 nike

我正在尝试使用 Bottle 将信息从 Web 表单发送到 Python。我正在使用 get 发送变量“test”,但是当我调用“test”的请求函数时,它没有返回。我一直在使用 bottle tutorial作为我的引用。

这是我的网络表单:

<form action="http://localhost:8080/page" method="get">
<input type="number" name="test" step="5">
<input type="submit" name="my-form" value="GO">
</form>

如果您在该字段中键入 1 并单击“开始”,您将转到以下 URL:

http://localhost:8080/page?test=10&my-form=GO

这是 Bottle python 代码:

@route('/page', method='GET')
def index():
testvar = request.forms.get('test')
return 'Hello %s' % testvar

据我了解,request.forms.get('test') 应该从 url 中的 test=10 检索值并将其传递到 testvar。但是,我收到的值为 none,这意味着 var 为空。

谢谢!

最佳答案

根据documentation , request.forms 只会收集 POST 和 PUT 参数:

forms

Form values parsed from an url-encoded or multipart/form-data encoded POST or PUT request body. The result is returned as a FormsDict. All keys and values are strings.

在你的例子中,你有 HTTP GET 表单,使用 request.params .

关于python - bottle request.forms.get 返回 None,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34857737/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com