Python:获取url?
获取当前所在网页的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
Python 区分大小写。
请注意,我自己没有尝试过此操作,但在查看文档后,我会冒险猜测您唯一的问题是
URL
的情况 - 确保它全部大写,您应该没问题。Try using
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.这是 Zope 的问题吗? context.absolute_url() 可能接近原始提问者的意图。
Is this a Zope question? context.absolute_url() might come close to what the original questioner intended.