ealeng
Menu
← All posts

Feb 24, 2020 · 1 min read

Get checkbox value in Flask and Jinja2

Here is how to get checkbox value from jinja2 template in a flask, first let’s create our jinja2 file: Then lets retrieve value from the form: Where rating is the name of input boxes

flaskpython

Here is how to get checkbox value from jinja2 template in a flask, first let’s create our jinja2 file:

<form action="" method="post">
        <input type="radio" id="1" name="rating" value="1">
        <label for="1">1</label><br>
        <input type="radio" id="2" name="rating" value="2">
        <label for="2">2</label><br>
        <input type="radio" id="3" name="rating" value="3">
        <label for="3">3</label><br>
        <input type="radio" id="4" name="rating" value="4">
        <label for="4">4</label><br>
        <input type="radio" id="5" name="rating" value="5">
        <label for="5">5</label><br><br>
        
        <p><input type=submit value=Next></p>
</form>

Then lets retrieve value from the form:

if request.method == 'POST':
        print(request.form['rating'])

Where rating is the name of input boxes

Learning something useful?

New labs, articles, and videos on evaluating and testing AI systems come out regularly. Follow along so you don't miss the next one.