How do I place an HTML link what refers to the current page, and which adds additional GET parameters (or overwriting existing ones, if they already exist)?
Right now I have something like:
<a href="{{ request.path }}?Key=Value"> My Link </a>
Currently, request is passed to the page. If request.path is https://stackoverflow.com/, then the resulting link becomes https://stackoverflow.com/?Key=Value
The problem?
But of course, if the current URL is https://stackoverflow.com/?PrevKey=PrevValue then it becomes:
Notice the incorrect second question mark — it should in fact be:
Furthermore, if there is already a key with the same name, then instead of overwriting it, my current solution ignores it — which is wrong.
How do I solve these two problems?
You’ll need a custom tag. There are a couple on djangosnippets – this one looks pretty comprehensive.