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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-query-params-1.0.0.tar.gz.
File metadata
- Download URL: django-query-params-1.0.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e6cc1293c9c8be0ac4869e9e1c5bc6d5ef090e7ce94cfbbc3697ca67f399aa8
|
|
| MD5 |
75010c39c3ac6bc60bc00f414907ac65
|
|
| BLAKE2b-256 |
ca1140751be221083ed3021e1192ba9dbf318c410a5bc530fda59e2106c85b7d
|
File details
Details for the file django_query_params-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_query_params-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e672761d68356943bdf805d063e5ccc7886b438402c293b911aca0ff7df2a13f
|
|
| MD5 |
2d27b753853ceba5768e456fbb64ea19
|
|
| BLAKE2b-256 |
0494ff2f6233e4d6904be6c5e924e5c5ad62ea45401f1fa98401377abd44a45d
|