문제

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

도움이 되었습니까?

해결책

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)

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top