Skip to content

Instantly share code, notes, and snippets.

@Xowap
Created June 27, 2015 10:39
Show Gist options
  • Save Xowap/dc381a7a6172bf313cb6 to your computer and use it in GitHub Desktop.
Save Xowap/dc381a7a6172bf313cb6 to your computer and use it in GitHub Desktop.
Django QueryString patch template tag
<a href="?{% qspatch page=clients.paginator.num_pages %}"><span>{{ clients.paginator.num_pages }}</span></a>
from django.template import Library
register = Library()
@register.simple_tag(takes_context=True)
def qspatch(context, **kwargs):
qs = context.request.GET.copy()
for k, v in kwargs.items():
if k in qs:
qs.pop(k)
qs[k] = v
return qs.urlencode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment