[Fixed]-Django post checkbox data

24👍

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

0👍

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.

👤ar2015

Leave a comment