Google App Engine - 请求类query_string [英] Google App Engine - Request class query_string
问题描述
在Python和GAE中,我想问如何获取url中查询字符串的参数。
据我所知,query_string部分返回?后面的所有部分在网址中。所以我必须做的是将查询字符串拆分为&,并使用变量。
是否有任何其他方便管理查询字符串的方法?
您通常如何操作?
str_query = self.request.query_string
m = str_query.split('&')
a = m [0]
b = m [1]
c = m [2]
这样做,如果query_string没有任何值,它会抛出一个错误:
IndexError:list index out范围
您无需复杂化。您可以检索所有GET参数:
self.request.get('var_name')
或者,如果您想在一个列表中检索它们,您可以使用:
self.request.get_all()
你可以找到更多有关请求类此处的信息。
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
解决方案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.
这篇关于Google App Engine - 请求类query_string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!