[英]Key Error when trying to get header value
我只是想在flask中請求一個表單值。 我之前做了很多次都沒問題,但是我無法弄清楚為什么會出現這個關鍵錯誤。
我嘗試了很多事情,例如從get請求切換到post請求,但似乎沒有任何效果。
應用程序路線:
@app.route('/Exercise', methods = ['GET'])
def exercise():
test = request.form["title"]
print(test)
if test != None:
info = select(["*"],"Exercises",["Name"],"And",[test])
print(info)
return render_template('exercise.html')
HTML:
<body>
<form>
<h2 class="head" id="name" name="title"></h2>
<p class="lead">Details</p>
</form>
</body>
<script type="text/javascript" src="static/js/exercise.js"></script>
</html>
好的,所以感謝PRMoureu,我發現我需要使被調用的url包含我想通過flask獲得的字段。 下面的示例:window.location.href =“ / Exercise?title =” + name;
感謝您的幫助,不勝感激
由於您支持GET
方法,因此請僅嘗試訪問您的title
鍵,如下所示:
request.args.get('title')
而不是test = request.form["title"]
因為這是您在POST
方法中訪問title
鍵的方式。
希望有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.