[Django]-Django How to Exclude GET Parameters When Comparing Current Page to request.get_full_path

3👍

You can use request.path instead to compare the path of the requested page with the index url. This will not include the query string if there was any.

A string representing the full path to the requested page, not
including the scheme or domain.

request.get_full_path() returns the path along with the query string.

Returns the path, plus an appended query string, if applicable.

{% url 'index' as index %}

<div>
    {% if request.path == index %} # use request.path instead
        This is the index
    {% else %}
        This is not the index
    {% endif %}
</div>

0👍

{% if request.path == request.get_full_path %}

request.path will give you the relative path without your GET parameters

Leave a comment