Trying to use image in Flask website only shows broken img icon

Issue

Hi so I’m trying to upload an png image that I saved in my static folder as a background in my little flask website. But I’m unable to do so. Each time I get a image icon (like it can’t load it or something).

Here is the html code where I try to insert the png image.

<img src="{{ url_for('static', filename='bgcaf.png') }}" />

Here is the structure of my website folder (I’m trying to display the bgcaf.png in Cafinit.html).
[1]: https://i.stack.imgur.com/mEQL5.png

If I left out important info please let me know

Solution

url_for is a flask function it works in your py files but not on your templates,this would work just fine

<img src="static/bgcaf.png"/>

Answered By – Empty

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published