Flask returns static HTML templates under the root directory '/'

When instantiating the Flask class, do a small setting static_url_path=''. Setting static_url_path to an empty string is equivalent to setting all URL accesses in the root directory to the /static/ directory, so the static HTML template directly You can refer to /js/something.js instead of /static/js/something.js so troublesome

Although they are actually stored in the /static/ directory, only the mapping relationship has been modified

from flask import Flask

app = Flask(__name__, static_url_path='')

@app.route('/')
def index():
    return app.send_static_file('index.html')

if __name__ == '__main__':
    app.run()

Guess you like

Origin blog.csdn.net/Ghjkku/article/details/129525419