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)

More like this

  1. EasyFeed class by limodou 6 years, 2 months ago
  2. Format transition middleware by limodou 6 years, 2 months ago
  3. Url filter middleware by limodou 6 years, 2 months ago
  4. testdata tag for templates by showell 4 years ago
  5. Absolute URL Templatetag by johnboxall 4 years ago

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/] (Documetation / Request+Response)

#

guettli (on January 31, 2008):

sorry, above URL is broken. This one works:

Documentation / Request+Response

#

(Forgotten your password?)