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:
20 Python Applications in Real-World
Python is an incredibly versatile language. People use it for all kinds of things. The broad real-world use cases we’ll cover here are really just the tip of the iceberg!
Top Skills Required for Python Developers
Over the past few years, Python became one of the most preferred programming languages for a myriad of tasks, from web applications to data science and machine learning
Most Popular Web Frameworks
The framework plays an essential role in the field of web development and web applications. There are many frameworks in the market and choosing the right one is a tricky task.
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.