Flask web page cannot find image file Flask web page cannot find image file flask flask

Flask web page cannot find image file


The way your program is currently written, the image will be visible if you reorganize the project layout like this:

project├── app.py├── static│   └── image1.jpg└── templates    └── photo1.html

The fact that you want to use send_static_file to display photos suggests that photos are static resources. If that's the case, then it would be better to:

1) Move image1.jpg to static/photos/image1.jpg

2) Change the template like this:

<p> <img src="{{url_for('static', filename='photos/image1.jpg')}}"></p>

3) Drop the app.add_url_rule('/photos/<path:filename>', ...) in app.py


I just created a folder named "static" in the project folder and moved my images to it and my problem got solved.

app.pystatic   |----image.jpgtemplates   |----index.html

and changed index.html file like this:

<img src="/static/image.jpg">