Reputation: 101
for example, I can reverse a url in this way:
{% url 'home:index' %}
but if I need to compare a url in a if
sentence, like this:
{% if request.path == url %}
and I want to replace the url with a reverse one but I can't do this:
{% if request.path == {% url 'home:index' %} %}
So is there another way can solve this?
Thanks a lot !
Upvotes: 1
Views: 2438
Reputation: 32274
The url tag takes an argument as <var>
that saves the result of the reverse to a variable. You can then use this variable in your comparison
{% url 'home:index' as home_url %}
{% if request.path == home_url %}
Upvotes: 2