Home > Software design >  html image in folder not showing
html image in folder not showing

Time:10-11

structure:

root_project
   -templates
      -pictures
         img.png
      -home.html

   -flask_session.py

I am running a Flask app in flask_session.py and I want to display images in multiple flexbox containers, everything works fine if I use a link to an image, but when i use file path it just doesn't work

            <div >
                <img src="pictures/img.png" />
            </div>
            <div >
                <img src="/pictures/img.png" />
            </div>
            <div >
                <img src="./pictures/img.png" />
            </div>
            <div >
                <img src="img.png" /> <!-- I even tried putting the image into the same folder as my html files and also in the root file, it still didn't work -->
            </div>

no matter what i do i just keep getting 404's

"GET /pictures/img.png HTTP/1.1" 404 -

CodePudding user response:

The Images are in the pictures directory and your are trying to access them without root directory. 1)C:\Windows\image.png #your complete file directory would work 2)import os cwd = os.getcwd() full_path = os.path.realpath(file)

CodePudding user response:

Try building the directories like this:

app/static/img/your_img.jpg

I hope it helps.

  • Related