I am trying to load an image through static but getting 404 error.
Here’s my code
<img src="{{url_for('static', filename=images/cat.png)}}" alt="new image">
<img src="{{url_for('static' filename=photo.png)}}" alt="new photo">
all my filepaths seem to be correct but the image is still not loading. When i just use the normal way of putting an image in HTML, the image shows up. for ex –
<img src="/static/images/cat.png" alt="photo Image">
here’s the filepaths of the project in pycharm
2
Answers
I recommend to use
Direct Path
rather thanurl_for
in this case, and it would look something like this:However if you insist on using
url_for
, You need to use the correct syntax:You have an issue with your syntax, specifically with the quotes. Try this code instead: