A Django app providing template tags for query string management
Project description
django-query-params
Django app providing template tags and JavaScript functions for query string management.
Template Tag Library
To install the app, type:
(venv)$ pip install django-query-params
Then add "query_params"
to the INSTALLED_APPS
in the settings.
To use the template tags in templates:
{% load query_params_tags %}
{% modify_query [only_query_string] param_to_remove another_param_to_remove param_to_change="new-value" another_param_to_change="new-value" %}
{% add_to_query [only_query_string] param_to_remove another_param_to_remove param_to_add="new-value" another_param_to_add="new-value" %}
{% remove_from_query [only_query_string] param_to_remove another_param_to_remove="value" %}
JavaScript Library
{% load static %}
<script src="{% static 'query_params/js/query_params.js' %}"></script>
<script>
var url1 = modify_query(
location,
['param_to_remove', 'another_param_to_remove'],
{
param_to_change: 'new-value',
another_param_to_change: 'new-value'
},
only_query_string=false
);
var url2 = add_to_query(
location,
['param_to_remove', 'another_param_to_remove'],
{
param_to_add: 'new-value',
another_param_to_add: 'new-value'
},
only_query_string=false
);
var url3 = remove_from_query(
location,
['param_to_remove'],
{
another_param_to_remove: 'value'
},
only_query_string=false
);
</script>
Example
Let's say the current URL is:
https://example.com/posts/?page=2&sort=by-date&tag=environment&tag=sustainability
modify_query
{% modify_query page tag="ecological" %}
will render:
/posts/?sort=by-date&tag=ecological
and
{% modify_query only_query_string page tag="ecological" %}
will render:
?sort=by-date&tag=ecological
add_to_query
{% add_to_query page tag="ecological" %}
will render:
/posts/?sort=by-date&tag=ecological&tag=environment&tag=sustainability
and
{% add_to_query only_query_string page tag="ecological" %}
will render:
?sort=by-date&tag=ecological&tag=environment&tag=sustainability
remove_from_query
{% remove_from_query page tag="environment" %}
will render:
/posts/?sort=by-date&tag=sustainability
and
{% remove_from_query only_query_string page tag="environment" %}
will render:
?sort=by-date&tag=sustainability
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-query-params-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 699a414d5d99df9b72063bc6d05f66e02a5149648c36e6347109769b87316060 |
|
MD5 | 99d0716e4cd2c04ffc7851f2706d6852 |
|
BLAKE2b-256 | 0db3eb9d64a4056b8257a24e4d3163497773da41171adbf437586d8d4b896cfa |
Hashes for django_query_params-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375d68f509e233ea08d966d49234b8ac78cb74f2631ebc8fbfa1023d50da6488 |
|
MD5 | 11ac7fa5e16c254f0d941030918b94bb |
|
BLAKE2b-256 | c46e44e6d0ac7386eb52627e42d99c4ae62b1f19f8da9fea141e33b21690279e |