Skip to content Skip to sidebar Skip to footer

How To Return A List With Flask

I'm trying to build a web page with questions and answers of a survey stored in my database. I get from my database the questions and answers in two separate lists and I'd like to

Solution 1:

Try this:

@app.route('/show-quest')defshowquestion():
    questions = ['favourite color?','favourite color?','favourite color?','do you like pasta?','do you like pasta?']
    answers = ["red","green",'blue','yes','no']
    return render_template('question.html', questions=questions, answers=answers)

question.html

{% for question in questions %}
    <p>{{question[0]}}</p>
    {% for answer in answers[0:3] %}
        <p>{{answer}}</p>
    {% endfor %}
{% endfor %}

Post a Comment for "How To Return A List With Flask"