2 回答

TA贡献2019条经验 获得超9个赞
添加到@Harshal 的答案中,使用 curl 时,您似乎在错误地访问请求数据。由于请求的 Content-Type 设置为application/json
,因此您需要使用flask.request.json
-更多详细信息来访问请求数据
或者您可以curl
像下面这样更新命令,
curl -ib cookies.txt --request POST --data-urlencode "text=Comment sent from curl" http://localhost:8000/api/v1/p/3/comments/
在这种情况下,curl 将自动使用Content-Type application/x-www-form-urlencoded
,您的应用程序将能够使用flask.request.form

TA贡献2065条经验 获得超14个赞
您的 HTML 表单配置不正确。
您正在发送一个 GET 请求,而您的烧瓶只接受 POST。
flask.request.form["text"]
要求输入名为 text 的输入,但您的文本框没有任何名称。没有提交按钮。
您可以通过以下方式修复它:
<form id="comment-form" method="post">
<input type="text" value="" name="text" />
<input type="submit" />
</form>
如果您了解更多有关响应代码的信息,您可能会更容易调试:https ://developer.mozilla.org/en-US/docs/Web/HTTP/Status 。
由于您正在使用request.form,因此可以像这样简化 tour curl:
curl --form "text=some_text_here" http://localhost:8000/api/v1/p/3/comments/
希望这可以帮助。祝你好运。
添加回答
举报