Skip to main content

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&amp;tag=ecological

and

{% modify_query only_query_string page tag="ecological" %}

will render:

?sort=by-date&amp;tag=ecological

add_to_query

{% add_to_query page tag="ecological" %}

will render:

/posts/?sort=by-date&amp;tag=ecological&amp;tag=environment&amp;tag=sustainability

and

{% add_to_query only_query_string page tag="ecological" %}

will render:

?sort=by-date&amp;tag=ecological&amp;tag=environment&amp;tag=sustainability

remove_from_query

{% remove_from_query page tag="environment" %}

will render:

/posts/?sort=by-date&amp;tag=sustainability

and

{% remove_from_query only_query_string page tag="environment" %}

will render:

?sort=by-date&amp;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

django-query-params-0.4.0.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

django_query_params-0.4.0-py3-none-any.whl (8.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page