Is there any way to get the value of multiplecheckboxes that the rendering in for loop with django-template-language

Question:

How to get value of mutiplecheckboxes in django.

the below code showing the groups at frontend

{% for group in groups %}
  <tr><td>{{group.name}}</td>
  <td><input type="checkbox" name="superuser" id="group-{{group.id}}" value="{{group.id}}"></td>                                             
 </tr>
{% endfor %}

I want to get the values of all checked boxes at backend when I submit the record.

frontend

Asked By: Shubham Nagar

||

Answers:

here is a way that i used and worked, try this may help you 🙂

in your html file:

{% for group in groups %}
  <tr><td>{{group.name}}</td>
  <td><input type="checkbox" name="superuser[]" id="group-{{group.id}}" value="{{group.id}}"></td>                                             
 </tr>
{% endfor %}

and in your view:

checked_group=request.POST.getlist('superuser[]')

so the checked_group will be a list contains all checked group ids.

Answered By: Saeed Ramezani
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.