python - How to html input to Flask? -


i have html bit:

<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> 

and python code:

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') 

how go adding making button which, after has been clicked on + question 1 , 2 have been answered, opens new template results? in short, how make button saying "yup, questions have been answered, count values , return them in new html page"?

the flask quick start tutorial go trough http requests doesn't answer quetion in specific situation. googling yielded this stackoverflow thread didn't bring me anywhere.

you should able add submit button form post or data response action.

in case, want modify form tag definition to:

<form action="/quiz_answers" method="post"> 

and add submit button this:

<input type="submit" value="submit!" /> 

when user clicks, should generate post request http://your_server/quiz_answers.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -