0

I have a database of multiple-choice questions (4 choices) with correct keys. I put 10 of them on a page.

Now I want to check if each of them is True or False when I click "Submit" button. How can I do that?

My code is here:

{% block content %}
{% set i = namespace(value=1) %}
{% for question in questions.items %} 
<form action="{{ url_for('result') }}" method="POST">
    <article class="media content-section">
        <div class="media-body">
            <h5 class="article-metadata">[{{ question.question_id }}] Câu {{ i.value }}</h5> <br>
            <p class="article-content">{{ question.content }}</p>

            <br>
            <div style="width: 50%;float: left;max-width: 50%; word-wrap: break-word;;">
                <label><input type="radio" name="optradio" value="A"> A. {{ question.key_A }}</label>
            </div>

            <div>
                <label><input type="radio" name="optradio" value="B"> B. {{ question.key_B }}</label>
            </div>

            <div style="width: 50%;float: left; max-width: 50%; word-wrap: break-word;">
                <label><input type="radio" name="optradio" value="C"> C. {{ question.key_C }}</label>
            </div>

            <div>
                <label><input type="radio" name="optradio" value="D"> D. {{ question.key_D }}</label>
            </div>

        </div>
    </article>
    {% set i.value = i.value +1 %}
    {% endfor %}
    <br>
    <div>
        <button class="btn btn-info" type="submit" value="Done!"
                style="margin-bottom: 15%;width: 25%;">Done!</button>
    </div>
</form>
{% endblock %}
17
  • check request.form in Flask view/function Commented Dec 15, 2019 at 8:30
  • Could you explain more? I'm still confused about your idea! Commented Dec 15, 2019 at 8:33
  • it is not idea - it is standard method to work with any form. Browser sends form data to server and Flask on server get it in request.form - you should see it in any tutorial. Commented Dec 15, 2019 at 8:40
  • BTW: where do you have tag <form action="some_url" method="POST"> ? Commented Dec 15, 2019 at 8:42
  • 1
    request.form.get("otpradio-1"), request.form.get("otpradio-2"), ... request.form.get("otpradio-10") Commented Dec 15, 2019 at 11:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.