[英]How can I create a dynamic src url in html img tag?
<img src="https://openweathermap.org/img/wn/10d@2x.png">
src url 通過更改最后一部分動態變化,例如,將 10d@2x.png 更改為 11d@2x.png 可以獲得不同的圖標。 但是,我想使用 Jinja2 和 Z319C3206A7F10C17C646A53EZ 動態更改 html 中的 url
我嘗試使用
img src="https://openweathermap.org/img/wn/{{icon}}@2x.png"
並從服務器端發送圖標變量,但它不起作用
當您在代碼中使用render_template
時,請執行以下操作:
return render_template('mytemplate.html', icon='11d')
在您的模板中:
<img src="https://openweathermap.org/img/wn/{{ icon }}@2x.png">
請注意用於呈現變量的雙花括號。 請參閱文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.