我根据一个给定的列表制作不同大小的表,它是通过一个for循环和一个HTML中的flask生成的。我面临的问题是,我不知道如何检索输入到type=“number”表单中的值。下面是我的代码示例。
HTML代码:
<table>
<tr>
<th><h1>Name</h1></th>
<th><h1>Number</h1></th>
</tr>
{% for i in range(names|length) %}
<tr>
<td><h2>{{ names[i] }}</h2></td>
<td><form>
<input type="number" name="{{ i }}" placeholder="0" step="1" min="0" max="10" formmethod="post">
</form></td>
<td><form>
<input type="submit" class="btn" name="save_button" value="Save" formmethod="post">
</form></td>
</tr>
{% endfor %}
</table>
烧瓶代码:
@app.route('/', methods=['GET', 'POST'])
def phone():
names = ['Jacob', 'Joe', 'Billy', 'Sue', 'Sally']
if request.form.get('save_button'):
for name in names:
print(request.form.get('name')
return render_template('phone.html', names=names)
唯一的回报是“没有”。任何帮助都非常感谢。