Get the full request path

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)

Comments

robbie (on March 6, 2007):

To be a bit more redundant, you could make that:

def get_full_path(request):
    return 'http' + ('', 's')[request.is_secure()] + '://' + request.META['HTTP_HOST'] + request.path

...or better:

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

#

limodou (on March 6, 2007):

Thanks. I lost secure.

#

guettli (on January 31, 2008):

Current SVN has the method request.build_absolute_uri():

http://www.djangoproject.com/documentation/request_response/

#

guettli (on January 31, 2008):

sorry, above URL is broken. This one works:

Documentation / Request+Response

#

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.