我已经查看了有关此错误的所有其他问题,但要么解决方案不起作用,要么我已经按照解决方案所说的去做了。我的 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
提交
取消