1
I use this tag mostly for pagination links within my project, i.e. to retain everything but switch the page number for the numerical hyperlinks, youโll notice I trash the _pjax
param if it exists:
@simple_tag
def query_transform(request, **kwargs):
"""usages: {% query_transform request page=1 %}"""
updated = request.GET.copy()
for k, v in kwargs.iteritems():
updated[k] = v
# trash any pjax params, we never want to render those
try:
del updated['_pjax']
except KeyError:
pass
return updated.urlencode()
I think maybe you want something similar, and maybe the trick you were missing was to call copy
on the request.GET
dictionary and mess with that, rather than the URL.
Source:stackexchange.com