qurl: A django template tag to modify url's query string

Pablo Ricco
May 6, 2016

In search pages is common to show filters, pagination and other useful links around the results. So for that reason we wrote the qurl template tag to append, remove, replace or alter query string parameters.

The full documentation of qurl can be found at http://django-qurl-templatetag.readthedocs.io.

Quick Start

To install qurl run the following command.

pip install django-qurl-templatetag

After installation is done, add qurl_templatetag to the INSTALLED_APPS setting in your settings.py file:

INSTALLED_APPS = (
    # …
    'qurl_templatetag',
    # …
)

Usage

The following example show how to use the qurl template tag in a django template file.

{% load qurl %}

{% qurl url [param]* [as <var_name>] %}

Parameters:
        name=value: replace all values of name by one value
        name=None: remove all values of name
        name+=value: append a new value for name
        name-=value: remove the value of name with the value

Example:

    {% qurl '/search?page=1&color=blue&color=green' order='name' page=None color+='red' color-='green' %}
    Output: /search?color=blue&order=name&color=red

    {% qurl request.get_full_path order='name' %} 

Tests

To run the tests you need to install the requirements and the run the runtests.py script:

$ pip install -r requirements/test.pip
$ python runtests.py

Final notes

This is a open source project under MIT license and can be found in our github organization:

https://github.com/sophilabs/django-qurl-templatetag

"qurl: A django template tag to modify url's query string" by Pablo Ricco is licensed under CC BY SA. Source code examples are licensed under MIT.

Photo by Martin Shreder.

Categorized under open source / python / django.

We are Sophilabs

A software design and development agency that helps companies build and grow products by delivering high-quality software through agile practices and perfectionist teams.