reading multiple selection from checkbox fields

II have a form (poll) with some questions and each question can have two or more answers available. When I try to collect the answers sxelected in the checked boxes using response.POST I receive back a QueryDict with the choices selected but I can`t read them.

Please how do I do to get the choices selected?

If you’re using a Django form, you don’t need to interrogate response.POST - Django will have populated your form field with the selections that were made.

Thanks Ken, I’ll try using Django Forms.

To get the choices selected from a form with multiple checkboxes, you can use the getlist() method of the QueryDict object returned by request.POST . The getlist() method returns a list of values for a given key.

Hi Varsha, Thank you very much for your answer. It really worked.
I’ve also tested Ken’s answer and it worked too.
Thank you both for the help.

Hello sir i am facing a little different issue,
i am getting an empty list. Could please tell me what is wrong here,
{% for x in content %}

 
{{x.0}}
{{x.1}}
{{x.2}}

  <td style="background-color: white; border:1px solid white"><div class="form-check">
    <input
      type="checkbox"
      name="tag[]"
      value="{{x}}"
    />
  </div></td>
</tr>
{% endfor %}

and in views.py this fucktion i am calling when checked
def remove(request):
check_values = request.POST.getlist(‘tag’)
print(check_values)
# for i in check_values:
# check_values.remove(i)
return HttpResponseRedirect(reverse(“tasks:index”))

@DevCoder1309 - I suggest you open a new topic for your issue.

Note: When posting code, templates, error messages here, surround the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.