According to the Flask readme, blueprint static files are accessible at blueprintname/static
. But for some reason, it doesn't work.
My blueprint is like this:
app/frontend/views.py
:
frontend = Blueprint('frontend', __name__,
template_folder='templates',
static_folder='static')
@frontend.route('/') etc...
app/frontend/js/app.js
: my javascript
- Blueprint registered in Flask app (routes work and everything)
When I go to abc.com/frontend/static/js/app.js
, it just gives a 404.
When I follow the Flask readme to get my static files:
<script src="{{url_for('frontend.static', filename='js/app.js')}}"></script>
The output is
<script src="/static/js/app.js"></script>
Which doesn't work either. There's nothing in my root app/static/
folder.
I can't access any static files in my blueprint! Flask read me says that it should work!
admin = Blueprint('admin', __name__, static_folder='static')
By default the rightmost part of the path is where it is exposed on the web. Because the folder is called static here it will be available at the location of the blueprint + /static. Say the blueprint is registered for /admin the static folder will be at /admin/static.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…