I followed the instructions from How to serve static files in Flask, but still couldn\'t get it working.
Here\'s my project structure:
Project_path
Finally got it working. use flask.send_from_directory
from flask import send_from_directory
@app.route('/js/')
def serve_static(filename):
root_dir = os.path.dirname(os.getcwd())
return send_from_directory(os.path.join(root_dir, 'static', 'js'), filename)
It is now clear to me that flask really hate people putting app.py
or in my case main.py
into a subdirectory. Use send_static_file
only if your static folder is what flask thinks to be, i.e. a folder with name static
in the same directory with app.py.