Python Bottle how to read request parameters

I am using http://dingyonglaw.github.com/bootstrap-multiselect-dropdown/#forms to display a drop down menu with multiple checkboxes.

<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 the server side (bottle):

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

will give me only the "second value" and ignore the "first value". Is there a way to collect all filter values?

+7
source share
2 answers

Use the request.query.getall method .

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

+11
source

Hey i had the same problem and found a solution

I will write code that relates to your problem

HTML: (note, I'm not very experienced here, so there may be a mistake, but the basic structure is correct). Here we want to customize the "form action" and use method = GET

 <form action="/webpage_name" method="GET"> <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> <input type="submit" name="save" value="save"> </form> 

Python: the "all_filters" variable will take all the data from the "filters" variable from the bottle import request

 @route('/webpage_name', method='GET') def function_grab_filter(): if request.GET.save: all_filters = request.GET.getall('filters') for ff in all_filters: fft = str(ff[0:]) # you might not need to do this but I had to when trying to get a number do soemthing.... 
0
source

All Articles