I'm using a checkbox form in my template and in my view im trying to check if the box has been checked or not I have the following code in my view:
if request.POST['check'] == True:
but then it throws an error if it is unchecked. How do i check if there is a value 'check' in my post data?
Thanks
The Python docs are your friend:
if request.POST.get('check', False):
...do stuff...
You could also do this (more Python docs):
if "check" in request.POST:
... do stuff...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With