1

I am building my first Flask application on local machine and have issues with path to images that I use in my HTML.

My folder structure is very simple:

-templates folder
     -assets folder
         - cover.jpeg
         - index.html

In my index.html I use relative path assets/cover.jpeg which should show a picture in my homepage. When I refresh homepage, it shows image placeholder only. When I open this pic in a new tab, it opens URL:

http://127.0.0.1:5000/assets/cover.jpeg

and displays:

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

I then tried full path to core folder of my project /templates/assets/cover.jpeg and got same thing, pointing now at

http://127.0.0.1:5000/templates/assets/cover.jpeg

It is probably something really silly, but I cannot make my picture displayed.

Scott
  • 1,863
  • 2
  • 24
  • 43
  • If your homepage is index.html, then you can just provide the path as "assets.jpeg" which should suffice. – ayrusme Feb 12 '18 at 11:57
  • If I use only 'cover.jpeg' (I believe this is what you meant), the picture's url is 'http://127.0.0.1:5000/cover.jpeg' and it does not show picture as well – Dmitry Khavanskiy Feb 12 '18 at 12:08
  • Okay, you want to return an image from a flask app. This is possible by using send_file in flask. – ayrusme Feb 12 '18 at 12:16
  • READ: https://stackoverflow.com/questions/8637153/how-to-return-images-in-flask-response – ayrusme Feb 12 '18 at 12:16
  • Solution was found. It was reeeaaally silly, but I am a beginner and this is what they do, right? =)) I created 'static' folder and used path like 'static/assets/cover.jpg' – Dmitry Khavanskiy Feb 13 '18 at 12:41

0 Answers0