简体   繁体   中英

Include with url variable in Django template

I have a "create new object" button in a template file.

I want to include the button several places at my website but I want to include the template with a link.

I've tried

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

but I want to use the benefits from {% url 'create_new_item' %} .

Can I do something like

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

Try with {% url ... as var %} syntax. Example:

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

Docs link here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM