如何循环查看视图中的复选框值。
这是我到目前为止所尝试的:
if request.method == 'POST':
form = SomeForm(request.POST)
# Check we have valid data before saving trying to save.
if form.is_valid():
data = form.cleaned_data
groups = data['thischeckbox']
for item in groups:
print(item)
但这会产生 KeyError 。
答案 0 :(得分:1)
if request.method == 'POST':
form = SomeForm(request.POST)
# Check we have valid data before saving trying to save.
if form.is_valid():
data = form.cleaned_data
groups = data['thischeckbox'].split(",")
for item in range(len(groups))
print(groups[item])