-1

I'm working on a flask app, and the problem that I'm struggling now is that any local path doesn't seem to work within the html file
The structure is like this:

Code/app.py Code/enternew.html Code/one.jpg Code/styles.css

and right now in my html file, I'm trying to load the css file and images in using <link type="text/css" href="styles.css" rel="stylesheet"/> and <img src="one.jpg" >

but neither works

alternatively if I copy the css code to in the part it works, if I use an online picture it also works, such as <img src="https://www.w3schools.com/images/picture.jpg">

but if i use a local path nothing seems to load. Does anyone have any idea what could be the issue? thank you!

davidism
  • 121,510
  • 29
  • 395
  • 339
dc3636
  • 1

1 Answers1

0

You can't link static files from the root directory like that. By default Flask will set up ./static as the directory from which to serve files from. Just like it sets up ./templates directory to look for templates.

Make a folder called static on your app directory and move your files there. Then link them with href="static/<your_file>".

Have a look at the project layout that Flask proposes here -> https://flask.palletsprojects.com/en/2.0.x/tutorial/layout/

RoachLok
  • 46
  • 3