I am using flask and I have around 6 web apps in my repository and so I am trying to pull out all the mutually used .css and .js files into a library directory so my directory structure looks like this:
lib/
static/
css/
my-css.css
js/
images/
my-image.jpg
webapps/
webapp_1/
src/
webapp_1/
main.py
templates/
base.html
main.html
other.html
webapp_2/
same as webapp_1 more or less
.
.
.
etc
So from base.html I need to reference the static directory in some form like so:
<link rel='stylesheet' href='../../../../../lib/static/css/my-css.css'>
<link rel="stylesheet" href="../../../../../lib/static/images/my-image.jpg">
And this works when I have a plain HTML file but not when I use it as a template through Flask. Is there something I need to change or some way I can use these files?
In app.py:
app = Flask(__name__, static_folder='../static')
Then in your templates:
<link rel='stylesheet' href='/static/css/my-css.css'>
<link rel="stylesheet" href="/static/images/my-image.jpg">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With