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.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73533db4082ae939037c7bf5793ae1e5082b9051593837335d34d788087f696f |
|
MD5 | 008e43cf0d75ad8f570c03af0d14d181 |
|
BLAKE2b-256 | a84ad93f66a08547ced02fcd15384afacdba304df947602f5b853b7082b1c0c9 |
Hashes for django_query_params-0.5.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28d4e3b43ef4188e07d45475b1b75abb9d826a7deddf238beb47548489465e21 |
|
MD5 | c17098ae9929f56e1f2212d08614a11d |
|
BLAKE2b-256 | 7aadbf59774dda78521ed5bd66218dc7b4b02f46b5e8d5e684928718189eac0d |