0

hope you are all doing well.

Im working on api project using python and flask. The question I have to ask is, how can I get the values of multiple query string parameter?

The api client is built in PHP, and when a form is submitted, if some of the parameters are multiple the query string is built like filter[]=1&filter[]=2&filter[]=3... and so on.

When I dump flask request, it shows something like (filter[], 1), (filter[], 2), (filter[], 3), it seems ok, but then when I do request.args.get('filter[]') it returns only the first item in the args ImmutableDict, filter[]=1, and I can't access the other values provided.

Any help regarding this issue would be aprreciated. Happy programming!

Miguel Pinto
  • 447
  • 1
  • 3
  • 15

2 Answers2

1

For a MultiDict you can access all values for a given key with:

request.args.getlist('filter[]')

Documentation: https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.MultiDict.getlist

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
0

try this request.args.to_dict(flat=False) to convert