vahid abdi
vahid abdi

Reputation: 10288

Compare Django template variable with template tag

I want to compare the result of {{ request.get_full_path }} with {% url "admin:index" %} but i don't know the syntax for that. I tried

{% if request.get_full_path == {% url "admin:index" %} %}
{% if request.get_full_path == url "admin:index" %}

but in both case i get TemplateSyntaxError.

Upvotes: 0

Views: 813

Answers (1)

Jack Shedd
Jack Shedd

Reputation: 3531

You can use this templatetag snippet to capture the output of any tag.

With the above added to a templatetag lib in one of your apps, and loaded, you can do this:

{% captureas admin_url %}{% url "admin:index" %}{% endcaptureas %}
{% if request.get_full_path == admin_url %}

Upvotes: 1

Related Questions