I'm using a GET parameter in my Django app to pass in information, that I want to be preserved in future links using Django's {% url %}
template tag.
In my case, this is to allow view-only access within the app.
Example URL:
https://my.app/entry/123?key=abcdef
An example link on that page is already created like this:
<a href="{% url 'entry_detail' entry.id %}">View more details</a>
Desired result:
I would like Django's URL template tag to automatically preserve any GET parameters named key
throughout the app. In this case, it would generate new URLs with that same parameter applied. For example:
https://my.app/entry/123/details?key=abcdef
Workarounds
This blog post and this gist solve the problem by creating a new template tag and using that instead of Django's url
template tag.
Is that really the best solution? I'd end up having to replace every instance of {% url %}
throughout my app with my own tag. It also wouldn't fix the use of reverse()
.