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

  1. Serve static media files from app/media subdirectory by adamlofts 6 years, 7 months ago
  2. Get the referer view of a request by arthurfurlan 5 years, 10 months ago
  3. Database file storage by powerfox 6 years, 1 month ago
  4. FilterManager by sergejdergatsjev 6 years, 3 months ago
  5. server with debugging backdoor by teepark 6 years, 5 months 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.

#

noomz (on September 15, 2014):

You can use built-in function build_absolute_url()

#

Please login first before commenting.