Google App Engine - query of query_string class

In Python and GAE, I would like to ask how to get query string parameters in a url. How do I know the query_string part returns the whole part after "?" in the url. So I need to break the query string into "&" and use the variables. Is there any other convenient way to control the query string? How do you usually do this?

str_query = self.request.query_string m = str_query.split('&') a = m[0] b = m[1] c = m[2] 

Executing this path, in case the query_string does not have any values, it generated an error:

 IndexError: list index out of range 
+6
python google-app-engine
source share
2 answers

You do not need to complicate the work. You can get all GET parameters with:

 self.request.get('var_name') 

Or, if you want to get them all in one list, you can use:

 self.request.get_all() 

More about this class can be found here .

+18
source share

If you want to iterate over all the parameters of your query, you should do something like this:

 for argument in self.request.arguments(): values = self.request.get_all(argument) # do something with values (which is a list) 

Or you can create your own dict containing all the data:

 params = {arg: self.request.get_all(arg) for arg in self.request.arguments()} 
0
source share

All Articles