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']
            for item in groups:
                print(item)

但这给出了KeyError

4

1 回答 1

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])
于 2013-03-20T16:41:14.113 回答