[Answer]-For a checkbox with multiple values in my html template how to access it through python code?

0👍

If u want to get array from html in Django view u need to use

checked = request.POST.getlist('ck1[]')

or

checked = request.POST.getlist('ck1')

getlist method will convert all selected values into python list

1👍

Please don’t use PHP syntax when you’re writing Django. name="ck1[]" is a PHP-ism that’s completely unnecessary.

If you want the field to be called ck1, just call use name="ck1", and use `request.POST.getlist(‘ck1’) in your view.

If you really have to use that horrible bracket syntax, you’ll need to use request.POST.getlist('ck1[]'), because Django quite sensibly believes that the name you use in the HTML is the name you should get in the POST data.

Leave a comment