Login

Get the full request path

Author:
limodou
Posted:
February 27, 2007
Language:
Python
Version:
Pre .96
Tags:
request-path
Score:
4 (after 6 ratings)

The result maybe:

http://localhost/test/

And for request.path, it will not include the domain field(http://localhost).

1
2
3
def get_full_path(request):
    full_path = ('http', ('', 's')[request.is_secure()], '://', request.META['HTTP_HOST'], request.path)
    return ''.join(full_path)

More like this

Comments

robbie (on March 6, 2007):
<p>To be a bit more redundant, you could make that:</p> <pre>def get_full_path(request): return 'http' + ('', 's')[request.is_secure()] + '://' + request.META['HTTP_HOST'] + request.path </pre> <p>...or better:</p> <pre>def get_full_path(request): full_path = ('http', ('', 's')[request.is_secure()], '://', request.META['HTTP_HOST'], request.path) return ''.join(full_path) </pre>

#

limodou (on March 6, 2007):
<p>Thanks. I lost secure.</p>

#

noomz (on September 15, 2014):
<p>You can use built-in function build_absolute_url()</p>

#

Please login first before commenting.