2

i'm using Flask with Python and want to insert an Image.
That works fine with following command:

{{ url_for('static', filename='path/to/img.jpg') }}

But now i want to insert an image in a loop (like for articles) and need the path out of a variable like:

{{ article.header_img_path }}

How can i insert a variable path into the

{{ url_for('static', filename='path/to/img.jpg') }}

command?
Something like that:

{{ url_for('static', filename=' {{ article.header_img_path }} ') }}


Is there a better way to do that or is just my syntax corrupt?


Thanks for your advise!

davidism
  • 121,510
  • 29
  • 395
  • 339
Favnyr
  • 353
  • 2
  • 11

1 Answers1

3

The variable should be passed to filename without quotes or braces.

{{ url_for('static', filename=article.header_img_path) }}
davidism
  • 121,510
  • 29
  • 395
  • 339
Favnyr
  • 353
  • 2
  • 11