gpt4 book ai didi

python - 为什么显示 BadrequestKeyError?

转载 作者:行者123 更新时间:2023-12-01 06:56:25 24 4
gpt4 key购买 nike

我正在做一个小项目 - 提醒系统。我有一个表单,它接受用户的值并将其插入数据库表中。从文本框中获取值时出现问题。下面是我的代码,我还给出了出现的错误。

<form method="POST" action="">
<input type="hidden" name="unique" value="{{session.UID}}" disabled="true">
<button type="submit" class="btn btn-primary">Confirm</button>
</form>

这是我的模板

@app.route('/home/set_reminder',methods=['POST'])
@is_logged_in
def set_reminder():
if request.method=='POST' and form.validate():
uid = request.form['unique']

我在这一行中收到错误 uid = request.form['unique']。不明白为什么它无法获取值。

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'unique'

这就是出现的错误。请帮帮我。

最佳答案

在您的 html 中,uid 输入已禁用,因此浏览器不会在 POST 请求正文中发送 uid。当您尝试访问 request.form.uid 时,这会导致错误 - 它不存在。

如果浏览器必须返回值,您可以使用readonly而不是disabled

参见this answer有关 BadRequestKeyError 的更多信息。

关于python - 为什么显示 BadrequestKeyError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58788990/

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