Is there a way to get the current page URL and all its parameters in a Django template?
For example, a templatetag that would print a full URL like /foo/bar?param=1&baz=2
/foo/bar?param=1&baz=2
Write a custom context processor. e.g.
def get_current_path(request): return { 'current_path': request.get_full_path() }
add a path to that function in your TEMPLATE_CONTEXT_PROCESSORS settings variable, and use it in your template like so:
TEMPLATE_CONTEXT_PROCESSORS
{{ current_path }}
If you want to have the full request object in every request, you can use the built-in django.core.context_processors.request context processor, and then use {{ request.get_full_path }} in your template.
request
django.core.context_processors.request
{{ request.get_full_path }}
See:
1.4m articles
1.4m replys
5 comments
57.0k users