【发布时间】:2021-05-28 07:40:54
【问题描述】:
晚上好,
我希望有人知道我的问题的答案,即将表中的所有检查行放入多维列表(提交后)?
我知道我可以做这样的事情来获取 - 例如 - 所有检查的 id 到一个列表中:
模板:
<form action="" method="post">
{% csrf_token %}
<div class="table-wrapper">
<table class="table table-hover">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">id</th>
<th scope="col">country</th>
<th scope="col">continent</th>
<th scope="col">...</th>
</tr>
</thead>
<tbody>
{% for item in data %}
<tr>
<td>
<input type="checkbox" name="list_gap" value="{{ item.id }}">
</td>
<td>{{ item.id}}</td>
<td>{{ item.country }}</td>
<td>{{ item.continent}}</td>
<td>...</td>
views.py
if request.method == 'POST':
checked_data = request.POST.getlist('list_gap')
但如前所述,这只会让我得到一个已检查 ID 的列表!有没有办法将所有行的数据放入多维列表中,例如like..?
list_checked = [
[1, 'country', 'continent', '...'],
[2, 'country', 'continent', '...'],
[3, 'country', 'continent', '...'],
...
]
感谢您的帮助,祝您晚安!
【问题讨论】:
标签: python html django html-table submit