[Django]-How do I get the values of all selected checkboxes in a Django request.POST?

92👍

Try this:

some_var = request.POST.getlist('checks')

some_var will contain [1,3,4] (those values that were checked)

40👍

This will fix your problem,

some_var = request.POST.getlist('checks[]')

If you write some_var = request.POST.getlist('checks') may not work properly.

1👍

this is will work:

<input type="checkbox" name="checks[]" value="1" />
<input type="checkbox" name="checks[]" value="2" />
<input type="checkbox" name="checks[]" value="3" />
<input type="checkbox" name="checks[]" value="4" />

views.py

some_var = request.POST.getlist('checks[]')

Leave a comment