Created
June 27, 2015 10:39
-
-
Save Xowap/dc381a7a6172bf313cb6 to your computer and use it in GitHub Desktop.
Django QueryString patch template tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="?{% qspatch page=clients.paginator.num_pages %}"><span>{{ clients.paginator.num_pages }}</span></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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