I have a certain link to a url in a Django template. I would like to grab all the GET parameters of the current page url and add them to the url of the template's link. The current page might have zero GET parameters.
3 Answers
13
votes
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 %}">
3
votes
1
votes