亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將靜態路徑傳遞給包含的模板

將靜態路徑傳遞給包含的模板

莫回無 2023-09-05 15:26:02
是否可以將靜態路徑作為變量傳遞給包含的模板?我需要在我的頁面上重復包含一個模板,但它總是帶有不同的徽標。例如:    {% 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' %}


查看完整回答
反對 回復 2023-09-05
  • 1 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號