How to Take Checkboxes in Python
When your form has multiple checkboxes with the same name
attribute, the request will have multiple values for that name when the form is submitted.
Your current code uses Request.get
to get a value, but this will only retrieve the first value if there is more than one. Instead, you can get all the values using Request.get_all(name)
(in webapp) or Request.get(name, allow_multiple=True)
(in webapp2). This will return a (possibly empty) list with all the values for that name.
Here's how you could use in in your code:
def post(self):
adjectives = self.request.get('adjective', allow_multiple=True)
for a in adjectives:
# increment count
self.adjective_count[a] += 1 # or whatever
# do more stuff with adjective a, if you want
# do other stuff with the request