I am looking to change which folder is recognized as the main static folder in a flask app while it is running. How could I go about this? Is there a particular config or parameter I can use?
Asked
Active
Viewed 1,799 times
-1
-
Does this answer your question? ==> https://stackoverflow.com/questions/20646822/how-to-serve-static-files-in-flask/20648053#20648053 – Federico Baù Aug 04 '20 at 14:43
-
2Does this answer your question? [How to serve static files in Flask](https://stackoverflow.com/questions/20646822/how-to-serve-static-files-in-flask) – toing_toing Aug 04 '20 at 21:33
2 Answers
0
Try
app = Flask(__name__, static_folder='static') # or rename to your own

General Grievance
- 4,555
- 31
- 31
- 45

GAEfan
- 11,244
- 2
- 17
- 33
0
Assume your have a flask app named myblog.py and the following directory structure:
assets is the static directory. myblog.py code looks like this:
from flask import Flask, render_template
app = Flask(__name__,
static_url_path='',
static_folder='app/assets',
template_folder='app/templates')
@app.route('/')
def index():
return render_template("index.html")
In index.html you access the static css file like this:
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">

jurgenizer
- 499
- 7
- 16