【发布时间】:2022-01-02 06:22:51
【问题描述】:
我有一个表格,里面有一个表格,里面显示了数据库查询的结果。该表有一个单选控件和两个按钮:一个用于编辑,另一个用于删除。为了让我修改一行,我必须选择相应行的收音机,然后按“删除”或“编辑”按钮。我想要做的是删除该单选按钮并使按钮直接带我编辑相应的行。当我删除单选按钮(这很明显)时,每一行的每个按钮只需要我编辑/删除第一个结果。
这是我的表格:
<form method="POST" id="form2" action="{{ url_for('edit_or_delete') }}">
<table class="table" id="tableSelect">
<tr>
<th></th>
<th>Manejar</th>
<th>Cantidad</th>
<th>Concepto</th>
<th>Fecha</th>
<th>Updated</th>
</tr>
<!-- loop for results -->
{% for s in mov %}
<tr><label for="id"></label>
<td class="center-align"><input type="radio" name="id" value="{{ s.id }}" required></td>
<td>
<button type="submit" name="choice" value="delete" class="btn btn-danger">Borrar</button>
<button type="submit" name="choice" value="edit" class="btn btn-primary">Editar</button>
</td>
<td>${{ s.cantidad }}</td>
<td>{{ s.concepto }}</td>
<td>{{ s.fecha }}</td>
<td>{{ s.udpated }}</td></label>
</tr>
{% endfor %}
</table>
<!-- end form-group -->
</form>
这是我的路线:
@app.route('/edit_or_delete', methods=['POST'])
def edit_or_delete():
id = request.form['id']
choice = request.form['choice']
movs = Movs.query.filter(Movs.id == id).first()
# two forms in this template
form1 = AddRecord()
form2 = DeleteForm()
return render_template('edit_or_delete.html', movs=movs, form1=form1, form2=form2, choice=choice)
【问题讨论】:
标签: flask