用Python获取当前网址 [英] Get current URL in Python
本文介绍了用Python获取当前网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用Python获取当前网址,
How would i get the current URL with Python,
我需要抓取当前网址,以便查询查询字符串,例如
I need to grab the current URL so i can check it for query strings e.g
requested_url = "URL_HERE"
url = urlparse(requested_url)
if url[4]:
params = dict([part.split('=') for part in url[4].split('&')])
这也是在Google App Engine中运行
also this is running in Google App Engine
推荐答案
试试这个:
self.request.url
另外,如果你只需要查询字符串,这将起作用:
Also, if you just need the querystring, this will work:
self.request.query_string
最后,如果您知道要查找的查询字符串变量,则可以执行此操作:
And, lastly, if you know the querystring variable that you're looking for, you can do this:
self.request.get("name-of-querystring-variable")
这篇关于用Python获取当前网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文