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.
- [Answer]-Django turn based browser game – database design to handle separate time steps
- [Answer]-Referencing a static file in a custom command
- [Answer]-Django JsonResponse from POST file upload
Source:stackexchange.com