Domanda

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')
È stato utile?

Soluzione

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')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top