gpt4 book ai didi

ajax - Angularjs + Flask-wtf : Bad request 400

转载 作者:行者123 更新时间:2023-12-03 17:31:32 25 4
gpt4 key购买 nike

我在 wtf-forms 中遇到了一个非常奇怪的问题,我使用 angularjs $http-module 发送请求。初始化 WTForm 后,我收到一个 错误请求:400 错误。出于测试目的,我禁用了 csrf 保护。我真的不知道在哪里寻找问题。以下是最小的失败:

Angularjs 服务发送请求:

var data = new FormData();
data.append('surname', _gifter.surname);
data.append('lastname', _gifter.lastname);
data.append('email', _gifter.email);
data.append('email_confirm', _gifter.email_confirm);
data.append('prize', gift.prize);

$http.post('ajax/claim/' + DataProvider.gift.id + '/', data)

flask 路线:
@app.route('/ajax/claim/<int:gift_id>/', methods = ['POST'])
def claim_gift(gift_id):
print("request:" + request.data)
claim_form = ClaimGiftForm(csrf_enabled=False)
return 'success'

WT表格:
class ClaimGiftForm(Form):
surname = TextField(
validators=[validators.Required()])
lastname = TextField(
validators=[validators.Required()])
email = EmailField(
validators = [
validators.email(),
validators.Required()])
email_confirm = EmailField(
validators = [
validators.Required(),
validators.EqualTo()])
prize = IntegerField()

当我打印请求时(参见“Flask route”),数据似乎没问题 - 一切都正确传输。但是在初始化表单时,我得到了上述错误。

编辑1:我刚刚发现,出于某种原因 request.form MultiDict 为空,尽管 request.data包含预期的数据。但是我不知道为什么会这样。

编辑2: pprint(request.data)给出:
-----------------------------109386632915471364402090498247\r\nContent-Disposition: form-data; name="surname"\r\n\r\ntheName\r\n
-----------------------------109386632915471364402090498247\r\nContent-Disposition: form-data; name="lastname"\r\n\r\ntheLastname\r\n
-----------------------------109386632915471364402090498247\r\nContent-Disposition: form-data; name="email"\r\n\r\nsomeone@somewhere.net\r\n
-----------------------------109386632915471364402090498247\r\nContent-Disposition: form-data; name="email_confirm"\r\n\r\nsomeone@somewhere.net\r\n
-----------------------------109386632915471364402090498247\r\nContent-Disposition: form-data; name="prize"\r\n\r\n12\r\n
-----------------------------109386632915471364402090498247--\r\n'

最佳答案

你的 JavaScript 有 email_confirmed但是表单的字段是email_confirm .

关于ajax - Angularjs + Flask-wtf : Bad request 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30851873/

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