在创建了Flask项目之后,如果不想用到模板引擎,想做前后端分离的项目时,就需要用到静态目录了。Flask的静态目录规定是static,也就是说所有的静态文件需要放到static文件夹下才能访问到。如下目录:
- app.py - static - index.html要访问index.html,需要通过Url: http://localhost:5000/static/index.html
也就是说要加上static路径进行访问。但这样又很不方便,因为要加static的话,访问html的url就显得有些“丑”了。这个时候,可以使用参数 static_url_path ,将其设置为 "" ,就可以跳过 static ,直接以 http://localhost:5000/index.html 访问。
app.py代码如下:
# 创建应用 app = Flask(__name__, static_url_path="") 转载请注明出处:
http://www.zgljl2012.com/2017/01/04/python-flaskjing-tai-mu-lu/