我已經查看了有關此錯誤的所有其他問題,但要么解決方案不起作用,要么我已經按照解決方案所說的去做了。我的 app.py 代碼:@app.route("/", methods=["POST", "GET"])def index(): if request.method == "POST": article_content = request.form["article_content"] threshold_val = request.form["threshold_input"] predictionCount = request.form["prediction_count"]HTML 代碼:<div> <div> <form action="/" method="POST"> <input class="Input-Box" type="text" name="article_content" /> <br /> <br /> <input type="submit" value="Find Systems" /> </form> </div> <div class="Settings"> <div style="align-items: center; display: inline-block;"> <h6>Threshold Value(0-1.0):</h6> <form action="/" method="POST"> <input type="text" name="threshold_input" /> </form> </div> <div style="align-items: center; display: inline-block;"> <h6>Number of predictions(1-24):</h6> <form action="/" method="POST"> <input type="text" name="prediction_count" /> </form> </div> </div> </div></div>有趣的是,Flask 從“article_content”獲取輸入沒有問題,但會匹配“threshold_input”和“prediction_count”。我檢查了 POST 方法,將 HTML 表單設置為 POST 方法,并確保 HTML 元素的名稱和 request.form 函數中的文本相同。任何幫助,將不勝感激。追溯如下:Traceback (most recent call last) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__ return self.wsgi_app(environ, start_response) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app response = self.handle_exception(e) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
1 回答

浮云間
TA貢獻1829條經驗 獲得超4個贊
您需要將所有表單控件放在一個form標簽下,并在submit其中添加一個輸入。您現在使用的提交輸入僅發送其封閉form標簽內的輸入,而不發送其他form標簽內的輸入。
https://www.w3.org/TR/html4/interact/forms.html#submit-format
<form action="/" method="POST">
<input class="Input-Box" type="text" name="article_content" />
<input type="text" name="threshold_input" />
<input type="text" name="prediction_count" />
<br />
<br />
<!-- This input submits everything inside of this form tag -->
<input type="submit" value="Find Systems" />
</form>
添加回答
舉報
0/150
提交
取消