我有一个表单(它是在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