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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32763741ee0620feb0dfd44a21441d51c30bd08d687705a6d247d741ab46d56f |
|
MD5 | 34b96270762cd9b29a2add9cb29a2d2c |
|
BLAKE2b-256 | 91c5351d86dc47df3cdca1996ba1dbe583dc146adc810631ba233c170d36d90a |
Hashes for django_query_params-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adc746b472fa221c590f5228299074bb9cec02608a71fe3b0f77062af56b8953 |
|
MD5 | 55061f1b3b87646234dca31651b87a48 |
|
BLAKE2b-256 | 6d3849fd0b58fe2fee212e1265aa6e5112e6204e377a2657c0c9c8a74b6c3dc0 |