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 %}
Use the as
option of the url
tag
{% 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With