亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Flask 的 BadRequestKeyError

Flask 的 BadRequestKeyError

臨摹微笑 2023-03-01 15:54:19
我已經查看了有關此錯誤的所有其他問題,但要么解決方案不起作用,要么我已經按照解決方案所說的去做了。我的 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>


查看完整回答
反對 回復 2023-03-01
  • 1 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號