[Django]-Get the values of multiple checkboxes in django

13πŸ‘

βœ…

In HTML, every form field needs a name attribute in order to be submitted to the backend. But for checkboxes, you can give them all the same name – but different values – so that they will be submitted as a list. So you can do this in your template:

<input type="checkbox" name="factura" value="{{ faktura.pk }}">

and in the view:

selected_values = request.POST.getlist('factura')

which will give you a list of the selected Factura ids.

Leave a comment