I want to server images from a folder that is a subfolder of 'static'
in my Python 3.7 Flask project.
I render the template using render_template('gallery.html', data=data)
where data
is a list of file paths. Gallery.html is a 3xn grid of pictures.
I tried <img src="{{ url_for({{data[0]}}) }}">
but that doesn't do anything. Just using {{data[0]}}
in the template displays the filepath, though.
Something that also didn't work:
def gallery():
data = get_files() # returns filenames in a list
render_template('gallery.html', data=data)
Template:
<img src="{{ url_for('static', filename='path/to/folder/{{data[0]}}' }}" >
How do I build the filepath and use them in a html <img>
attribute with url_for()
, so that my images are loaded correctly?