是否可以將靜態路徑作為變量傳遞給包含的模板?我需要在我的頁面上重復包含一個模板,但它總是帶有不同的徽標。例如: {% 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 %}這不行..除了創建一個模型來支持每個國家/地區實例的圖像屬性之外,還有其他解決方法嗎?
1 回答

開滿天機
TA貢獻1786條經驗 獲得超13個贊
您可以使用一個{% … as … %}子句來做到這一點:
{% 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' %}
添加回答
舉報
0/150
提交
取消