在 Python 中获取当前 URL

编程入门 行业动态 更新时间:2024-10-28 05:16:38
本文介绍了在 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

本文发布于:2023-11-23 11:23:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!