Max*_*lov 5 django checkbox django-templates django-views
我有一个包含一些数据库数据的表
<table id="id_list_table" class="table table-condensed">
<caption>Inputs list</caption>
<thead>
<tr>
<th>#</th>
<th id="input">Input</th>
</tr>
</thead>
<tbody id="fbody">
{%for input in InputsAll%}
<tr>
<td>{{ input.input }}</td>
<td>
<a class="btn btn-primary btn-xs" href="{% url 'edit' %}?input_num={{input.id}}" id="edit">edit</a>
<a class="btn btn-danger btn-xs" href="{% url 'delete' %}?input_num={{input.id}}" id="remove">remove</a>
<a class="btn btn-success btn-xs" href="{% url 'resolve' %}?input_num={{input.id}}"id="resolve">resolve</a>
<input type="checkbox" name="inputs" id="option{{input.id}}" value={{input.id}} />
</td>
</tr>
{%endfor%}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我想在每个字段中添加一个复选框,并传递选中数据的 id 来查看并进行组操作,而不是逐一删除项目。我添加了这个复选框
<input type="checkbox" name="inputs" id="option{{input.id}}" value={{input.id}} />
Run Code Online (Sandbox Code Playgroud)
我应该如何传递所有检查的值来查看?是这样的吗?
小智 7
视图.py
if request.method == 'POST':
#gives list of id of inputs
list_of_input_ids=request.POST.getlist('inputs')
Run Code Online (Sandbox Code Playgroud)
希望这可以解决您的大部分问题。查看此链接 复选框以获取项目列表,例如 Django 管理界面中的项目列表
| 归档时间: |
|
| 查看次数: |
8768 次 |
| 最近记录: |