Helper function and template tags for dealing with numeric url query strings in Django.
pip install django_url_helper- Add
django_url_helperto yourINSTALLED_APPS - You're all set!
In templates:
put {% load url_helper %} on top of your template.
given a variable in template url which resolves into https://some.django.site/somepath/?k=1
The following steps are applied and demostrated in order.
- Applying
{% add_param url 'page' '1' %}would resolve intohttps://some.django.site/somepath/?k=1&page=1 - Then,
{% toggle_param url 'page' '1' %}would toggle off thepage=1, resolving intohttps://some.django.site/somepath/?k=1 - Then,
{% toggle_param url 'page' '1' %}would toggle on thepage=1, which would resolve intohttps://some.django.site/somepath/?k=1&page=1 - Then,
{% reset_param url 'k' '2' %}would resetkto value2, resolves tohttps://some.django.site/somepath/?k=2&page=1 - Then,
{% remove_param url 'k' '2' %}would remove anyk=2query string in target url. In our case this would resolve intohttps://some.django.site/somepath/?page=1 - Finally,
{% purge_param url 'page' %}would remove any query string with keypage, this will give ushttps://some.django.site/somepath/
Tests are ran using pytest, any contibutions are welcomed.