Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine - Request class query_string

In Python and GAE, I would like to ask how to get the parameters of a query string in the url. As I know, the query_string part returns all the part after the "?" in the url. So what I have to do is to split the query string with "&", and use the variables. Is there any other convinient way to manage the query string? How do you normally do it?

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

Doing this way, in case, the query_string does not have any values, it threw an error:

IndexError: list index out of range
like image 791
Hoang Pham Avatar asked Sep 07 '09 21:09

Hoang Pham


1 Answers

You don't need to complicate. You can retrieve all GET parameters with:

self.request.get('var_name')

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

self.request.get_all()

You can find more info on the Request class here.

like image 121
rogeriopvl Avatar answered Nov 13 '22 19:11

rogeriopvl