[Answered ]-MultiValueDictKeyError at generated form element

1๐Ÿ‘

โœ…

If a checkbox is not checked, it is simply not part of the request. So if you tick answ2, and answ4, then answ0, answ1 and answ3 will not be part of the request.

You thus will look at:

if 'answ0' in request.POST:
    pass  # ๐Ÿ–˜ checked
else:
    pass  # ๐Ÿ–˜ not checked

Checkboxes are a bit tricky, just like date input for example. Therfore typically a Django Formย [Django-doc] is typically used at least to validate and clean the input.

Leave a comment