Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle a multiple select form field in python + webapp2?

I have a form built with python + webapp2 + jinja2. All the values submitted appear to be strings. One of the fields is a multiple select and only the first selected item gets submitted. Is there a way to have that field submitted as an array of all the selected values.

I have for the html template

<select name="some_list" multiple>
  <option value="red">Red</option>
  <option value="red">Blue</option>
  <option value="red">Yellow</option>
</select>

In the python class

some_list = []
some_list = self.request.get('some_list')
like image 895
Atilio Avatar asked Aug 14 '26 10:08

Atilio


1 Answers

The request object contains a MultiDict which means you can use another method to get all values passed for a given key. Try something like:

self.request.params.getall('some_list')
like image 138
Jesse Rusak Avatar answered Aug 16 '26 13:08

Jesse Rusak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!