Is it possible to get values ​​from a query string with the same name?

I want to know if it is possible to get values ​​from this query string?

'?agencyID=1&agencyID=2&agencyID=3'  

Why should I use a query string like this?
I have a form with 10 checkboxes. my user must send me the identifier of the news agencies that he or she is interested in. Therefore, to query a string, it contains several values ​​with the same name. the total number of news agencies is variable and they are downloaded from the database.
I am using Python Tornado to parse query strings.

+4
source share
3 answers

-, , ,

RequestHandler.get_arguments (name, strip = True)

. , . unicode.

,

ids = self.get_arguments('agencyID')

, get_arguments, get_argument, .


query = self.request.query
+9
>>> from urlparse import urlparse, parse_qs
>>> url = '?agencyID=1&agencyID=2&agencyID=3' 
>>> parse_qs(urlparse(url).query)
{'agencyID': ['1', '2', '3']}
+2

tornado.web.RequestHandler :

  • get_argument (id), "id".
  • get_arguments (id), 'id' , .

, , get_arguments - , .

+2

Source: https://habr.com/ru/post/1543167/


All Articles