在 Django 模板中包含 url 变量

Include with url variable in Django template

我在模板文件中有一个 "create new object" 按钮。

我想在我网站的多个位置包含该按钮,但我想包含带有 link 的模板。

我试过了

{% 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 %}

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

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

文档 link here.