How do I get the current url in web2py?

北城余情 提交于 2019-12-07 08:35:31

问题


In web2py how do I get the complete url of the current page? I want the (possibly rewritten) url that appears in the browser address bar.

e.g. http://www.example.com/products/televisions?sort=price&page=2


回答1:


The easiest method to generate this is probably:

URL(args=request.args, vars=request.get_vars, host=True)

You could also assemble the URL this way:

'%s://%s%s' % (request.env.wsgi_url_scheme, request.env.http_host,
               request.env.web2py_original_uri)



回答2:


I know this is an old thread - this is what it took for me in 2017 to get the original url:

url = '%s://%s%s' % (request.env.wsgi_url_scheme, request.env.http_host,
           request.env.request_uri)

Close to the previous answer but the uri was elsewhere.



来源:https://stackoverflow.com/questions/21827793/how-do-i-get-the-current-url-in-web2py

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!