我在模板文件中有一个“创建新对象”按钮。
我想在我网站的多个位置包含按钮,但我想包含带有链接的模板。
我试过了
{% 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 %}
文档链接 here .
关于python - 在 Django 模板中包含 url 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29650187/