Generating a url with the same GET parameters as the current page in a Django template
Include the django.core.context_processors.request
context processor in your settings.py
, then use the request
object in your template's links:
<a href="{% url 'my_url' %}?{{ request.META.QUERY_STRING }}">
This will cause links from a page without any GET variables to have a trailing ?
but that's harmless. If that's not acceptable, you could test for them first:
<a href="{% url 'my_url' %}{% if request.META.QUERY_STRING %}?{{ request.META.QUERY_STRING }}{% endif %}">