本文摘自:https://blog.csdn.net/u014030117/article/details/46508901
实例化Flask类的时候做一个小设置static_url_path=''
即可,把static_url_path
设置为空字符串相当于设置把所有根目录下URL的访问都关联到/static/
目录下,所以静态HTML模版中直接可以引用/js/something.js
而不是/static/js/something.js
这样麻烦
虽然他们实际上还是存放在/static/
目录下,只是修改了映射关系
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()
“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill
标 题:Flask在根目录'/'下返回静态HTML模版