[Fixed]-Django post checkbox data


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...


This is what I did:

request.POST.get('field_name', '') == 'on'

Note: another proposed solution

request.POST.get('check', False) # do not use it

led to this error for me:

['“on” value must be either True or False.']

when the checkbox is selected.


Leave a comment