mario199
mario199

Reputation: 406

How to put 'url' template tag into 'with'

I am trying to cache return value of {% url ..} function to a variable with with template tag.

here is my code: {% with path=url "show_cart" %} {% endwith %}

And with this code I get this exception: TemplateSyntaxError u'with' received an invalid token: u'"show_cart"'

Is it possible to assign result of url function to variable?

Upvotes: 1

Views: 563

Answers (1)

miki725
miki725

Reputation: 27861

You can do this. Not sure what Django version is required for this syntax:

{% url 'view' as the_url %}
{{ the_url }}

Doc here

Upvotes: 4

Related Questions