在Django模板中包含url变量

时间:2015-04-15 12:26:26

标签: python django django-templates django-template-filters

我在模板文件中有一个“创建新对象”按钮。

我想在我的网站上包含几个位置的按钮,但我想在模板中加入一个链接。

我试过

{% include "snippets/icon_add.html" with link="/create_new_item/" only %}

但我希望使用{% url 'create_new_item' %}带来的好处。

我可以做点什么吗

{% include "snippets/icon_add.html" with link={% url 'create_new_item' %} only %}

1 个答案:

答案 0 :(得分:11)

尝试使用{% url ... as var %}语法。例如:

{% url 'create_new_item' as the_url %}
{% include "snippets/icon_add.html" with link=the_url %}

文档链接here

相关问题