Python:获取url?

发布于 2024-09-09 08:40:11 字数 326 浏览 0 评论 0原文

获取当前所在网页的 URL 的最简单方法是什么?

例如,如果我有一个 python 函数,并且我从网页中调用它,那么获取 URL 的最佳方法是什么。也许一个更简单的问题是如何获取 URL 中传递的变量,即“?”之后。

我尝试过打电话:

def return_query(self):
    self.request.url

我也尝试过

def return_query2(self):
    self.request.query_string

但我收到请求的属性错误

Whats the simpliest way to obtain the URL of the webpage you are currently on?

For example if i have a python function and i call it from within a webpage, whats the best way to obtain the URL. What maybe an easier question how is how do you obtain the variables passed within the URL i.e. after the "?"

I've tried calling:

def return_query(self):
    self.request.url

I have also tried

def return_query2(self):
    self.request.query_string

But i get a attrbiute error for request

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恰似旧人归 2024-09-16 08:40:11

尝试使用

def return_query(self):
    return self.request.URL

Python 区分大小写。

请注意,我自己没有尝试过此操作,但在查看文档后,我会冒险猜测您唯一的问题是 URL 的情况 - 确保它全部大写,您应该没问题。

Try using

def return_query(self):
    return self.request.URL

Python is case-sensitive.

Note that I have not tried this myself, but after looking at the documentation, I would hazard a guess that your only problem is the case of URL - make sure it is all capitals and you should be fine.

写下不归期 2024-09-16 08:40:11

这是 Zope 的问题吗? context.absolute_url() 可能接近原始提问者的意图。

Is this a Zope question? context.absolute_url() might come close to what the original questioner intended.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文