我有一個表單(它是在index.html中創建的)。 然而,當我點擊提交時,我收到一個400錯誤請求錯誤。我認爲這與在瓶我的應用程序的路線做的,但我不能找出解決的辦法......使用Flask和HTML格式的錯誤請求
index.html中(節選):
<form class="demographic-form" action="/getsurveyresult" method="post"> Question: <br> <input type="checkbox" name="question" value="yes">Check this box! <br> <input type="submit" id="submitButton" value="Submit"> </form>
在應用.py:
from flask import *
import json
app = Flask(__name__)
app.debug = True
app.vars = {}
@app.route("/")
def index():
return render_template("index.html")
@app.route('/getsurveyresults', methods=['POST'])
def processData():
app.vars['question'] = request.form['question']
f = open('data.txt' ,'w')
f.write('question: %s\n' %(app.vars['question']))
f.close()
return render_template("getsurveyresults.html")
if __name__ == "__main__":
app.run()
我在與index.html相同的文件夾中有一個getsurveyresults.html腳本。 Index.html沒有渲染問題。
P.S.我試圖用行動代替行動= 「/ getsurveyresult」= 「{{url_for( 'getsurveyresult')}}」,但我有一個werkzeug.routing.BuildError - 如下圖所示
是的 - 我正在測試它沒有檢查任何框。太棒了!我包含了request.form.get,如果我不輸入任何內容,它不會再拋出錯誤。謝謝! – AllieCat