Shyngys Kassymov
Shyngys Kassymov

Reputation: 728

How to get select box option value in Flask?

I made a simple application on Pythonanywhere using Flask framework. When I submit a form, in the console logs I see that all information is transferred. But I don't need the name of selected item in select box, I need its value (id).

<div class="form-group">
    <label for="carCarcass" class="col-lg-6 control-label">Кузов</label>
    <div class="col-lg-6">
        <select class="form-control" id="carCarcass" name="carCarcass">
            <option value="0" SELECTED>-</option>
            {% for carcass in CARCASSES %}
                <option value="{{ loop.index }}">{{ carcass }}</option>
            {% endfor %}
        </select>
    </div>
</div>

When I try to get via request.form['carCarcass'] it returns the string that is between option tags.

How do I access the value?

Upvotes: 0

Views: 2865

Answers (1)

user9501250
user9501250

Reputation:

actually i get this like the below method.This will print the selected values in list.

name=request.form.getlist('carCarcass')
for x in name:
   print("x",x)

Upvotes: 0

Related Questions