是否可以將靜態(tài)路徑作為變量傳遞給包含的模板?我需要在我的頁(yè)面上重復(fù)包含一個(gè)模板,但它總是帶有不同的徽標(biāo)。例如: {% with img={% static 'img/dashboards/belgium_flag.svg' %} %} {% include 'dashboards/charts/country_block.html' %} {% endwith %} {% with img={% static 'img/dashboards/netherlands_flag.svg' %} %} {% include 'dashboards/charts/country_block.html' %} {% endwith %}這不行..除了創(chuàng)建一個(gè)模型來(lái)支持每個(gè)國(guó)家/地區(qū)實(shí)例的圖像屬性之外,還有其他解決方法嗎?
1 回答

開滿天機(jī)
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
您可以使用一個(gè){% … as … %}子句來(lái)做到這一點(diǎn):
{% static 'img/dashboards/belgium_flag.svg' as img %}
{% include 'dashboards/charts/country_block.html' %}
{% static 'img/dashboards/netherlands_flag.svg' as img %}
{% include 'dashboards/charts/country_block.html' %}
添加回答
舉報(bào)
0/150
提交
取消