In production, you don’t want to serve static files using the flask server. I suggest you use a proper web server to do that.
For dev, since you don’t want to use url_for
, you can try to initialize your flask app as below. This way, flask knows where your static files are.
app = Flask(__name__, static_folder="static")
@app.route('/<path:filename>')
def send_file(filename):
return send_from_directory(app.static_folder, filename)
See this post with a lot of info
Static files in Flask – robot.txt, sitemap.xml (mod_wsgi)