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).
我使用Flask框架在Pythonanywhere上创建了一个简单的应用程序。当我提交表单时,在控制台日志中,我看到所有信息都已传输。但是我不需要选择框中所选项目的名称,我需要它的值(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.
当我尝试通过request.form ['carCarcass']时,它返回选项标签之间的字符串。
How do I access the value?
我如何访问该值?
1 个解决方案
#1
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)
#1
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)