在 Python 中获取当前 URL [英] Get current URL in Python
本文介绍了在 Python 中获取当前 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用 Python 获取当前 URL,
How would i get the current URL with Python,
我需要获取当前的 URL,以便我可以检查它的查询字符串,例如
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 中获取当前 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文