我有这个html位:
<form action='quiz_answers'> <p> Question1? </p> <input type="radio" name="q1" value="2">Answer1</input> <input type="radio" name="q1" value="1">Answer2</input> <input type="radio" name="q1" value="0">Answer3</input> <input type="radio" name="q1" value="0">Answer4</input> <p> Question2? </p> <input type="radio" name="q2" value="2">Answer1</input> <input type="radio" name="q2" value="1">Answer2</input> <input type="radio" name="q2" value="0">Answer3</input> <input type="radio" name="q2" value="0">Answer4</input> </form>
和这个python代码:
from flask import Flask,render_template,request @app.route('/quiz') def quiz(): return render_template('quiz.html') @app.route('/quiz_answers',methods=['POST']) def quiz_answers(): q1 = request.form['q1'] q2 = request.form['q2'] q4 = request.form['q4'] q5 = request.form['q5'] if __name__ == "__main__": app.debug = True app.run(host='0.0.0.0')
我如何添加一个按钮,在点击问题1和2后,按钮打开一个带有结果的新模板?简而言之,我如何制作一个按钮说“是的,问题已被回答,计算值并将它们返回到新的HTML页面”?
Flask快速入门教程确实通过HTTP请求,但在这种特定情况下不回答我的问题.谷歌搜索只产生了this stackoverflow thread,这并没有带我到任何地方.