Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Bottle how to read request parameters

I am using http://dingyonglaw.github.com/bootstrap-multiselect-dropdown/#forms to display a dropdown with multiple check boxes.

<li>
  <label>
    <input type="checkbox" name="filters" value="first value">
    <span>First Value</span>
  </label>
</li>

<li>
  <label>
    <input type="checkbox" name="filters" value="second value">
    <span>Second Value</span>
  </label>
</li>

This is the resulting URL:

http://example.com/search?filters=first+value&filters=second+value

On Server side (bottle):

terms = unicode (request.query.get ('filters', ''), "utf-8")

will give me only "second value" and ignore "first value". Is there a way of collecting all the 'filters' values?

like image 521
martincho Avatar asked Jul 26 '12 14:07

martincho


1 Answers

Use the request.query.getall method instead.

FormsDict is a subclass of MultiDict and can store more than one value per key. The standard dictionary access methods will only return a single value, but the MultiDict.getall() method returns a (possibly empty) list of all values for a specific key.

like image 64
Martijn Pieters Avatar answered Nov 09 '22 18:11

Martijn Pieters