4
如何將一個url分配給一個變量到模板中? 我已經試過:django-template將url分配給一個變量
{% with url_news = url 'news' %}
和
{% with url 'news' as url_news %}
如何將一個url分配給一個變量到模板中? 我已經試過:django-template將url分配給一個變量
{% with url_news = url 'news' %}
和
{% with url 'news' as url_news %}
使用as
選項url
tag
{% url 'news' as the_url %}
{% if the_url %}
<a href="{{ the_url }}">Link to optional stuff</a>
{% endif %}
注意的是,當你使用這個語法,它會悄悄如果URL失敗無法解決。
如何定義多個網址? – Clayton
@Clayton你可以多次使用url標記,例如'{%url'first_view'作爲first_url%} {%url'second_view'作爲second_url%}'。 – Alasdair