2 回答

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊
添加到@Harshal 的答案中,使用 curl 時(shí),您似乎在錯(cuò)誤地訪問請(qǐng)求數(shù)據(jù)。由于請(qǐng)求的 Content-Type 設(shè)置為application/json
,因此您需要使用flask.request.json
-更多詳細(xì)信息來訪問請(qǐng)求數(shù)據(jù)
或者您可以curl
像下面這樣更新命令,
curl -ib cookies.txt --request POST --data-urlencode "text=Comment sent from curl" http://localhost:8000/api/v1/p/3/comments/
在這種情況下,curl 將自動(dòng)使用Content-Type application/x-www-form-urlencoded
,您的應(yīng)用程序?qū)⒛軌蚴褂?code>flask.request.form

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
您的 HTML 表單配置不正確。
您正在發(fā)送一個(gè) GET 請(qǐng)求,而您的燒瓶只接受 POST。
flask.request.form["text"]
要求輸入名為 text 的輸入,但您的文本框沒有任何名稱。沒有提交按鈕。
您可以通過以下方式修復(fù)它:
<form id="comment-form" method="post">
<input type="text" value="" name="text" />
<input type="submit" />
</form>
如果您了解更多有關(guān)響應(yīng)代碼的信息,您可能會(huì)更容易調(diào)試:https ://developer.mozilla.org/en-US/docs/Web/HTTP/Status 。
由于您正在使用request.form,因此可以像這樣簡(jiǎn)化 tour curl:
curl --form "text=some_text_here" http://localhost:8000/api/v1/p/3/comments/
希望這可以幫助。祝你好運(yùn)。
添加回答
舉報(bào)