Reputation: 3198
How can I assign an url to a variable into a template? I've tried:
{% with url_news = url 'news' %}
and
{% with url 'news' as url_news %}
Upvotes: 4
Views: 1924
Reputation: 309089
Use the as option of the url tag
as
url
{% url 'news' as the_url %} {% if the_url %} <a href="{{ the_url }}">Link to optional stuff</a> {% endif %}
Note that when you use this syntax, it will fail silently if the url can't be resolved.
Upvotes: 12