簡體   English   中英

在 Django 模板中包含 url 變量

[英]Include with url variable in Django template

我在模板文件中有一個“創建新對象”按鈕。

我想在我的網站的多個位置包含該按鈕,但我想包含帶有鏈接的模板。

我試過了

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

文檔鏈接在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM