How to get the current URL within a Django template

djangodjango-templates

I was wondering how to get the current URL within a template.

Say my current URL is:

.../user/profile/

How do I return this to the template?

Best Answer

Django 1.9 and above:

## template
{{ request.path }}  #  -without GET parameters 
{{ request.get_full_path }}  # - with GET parameters

Old:

## settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
)

## views.py
from django.template import *

def home(request):
    return render_to_response('home.html', {}, context_instance=RequestContext(request))

## template
{{ request.path }}