Django-template assigns url to a variable

How to assign a url to a variable in a template? I tried:

{% with url_news = url 'news' %} 

and

  {% with url 'news' as url_news %} 
+4
source share
1 answer

Use as parameter of url tag

 {% url 'news' as the_url %} {% if the_url %} <a href="{{ the_url }}">Link to optional stuff</a> {% endif %} 

Note that using this syntax will fail if the URL cannot be resolved.

+10
source

Source: https://habr.com/ru/post/1483746/


All Articles