1
<img src="https://openweathermap.org/img/wn/10d@2x.png">

The src url changes dynamically by changing the last part for example, by changing 10d@2x.png to 11d@2x.png a different icon can be obtained. However, I want to dynamically change the url in html using Jinja2 and flask

I tried using

img src="https://openweathermap.org/img/wn/{{icon}}@2x.png"

and send the icon variable from server side, but it won't work

Umesh N
  • 31
  • 6

1 Answers1

1

When you use render_template in your code, do something like that:

return render_template('mytemplate.html', icon='11d')

In your template:

<img src="https://openweathermap.org/img/wn/{{ icon }}@2x.png">

Note the double-curly braces to render the variable. See the documentation

Corralien
  • 109,409
  • 8
  • 28
  • 52