My Flask设置目前正是这样的


 + project
 app.py
 +模板
的index.html
 +脚本
 mn.js



 mn.js
如下所示:
alert(“hello”);



 index.html
指的是像这样的脚本:
< head>
 < script src =“script / mn.js”>
< / head>



 app .py
的设置如下:
app = Flask(__ name __,template_folder ='template')



 我运行Flask并转到localhost URL。但 alert()
永远不会触发。我在浏览器的控制台中看到 404
错误,指出它无法找到 http://127.0.0.1:5000/script/mn.js
。
如果不更改 index.html
中< script>
标记的内容,如何让Flask加载 mn。 JS 代码>
答案 0 :(得分:0)
在script
文件夹中创建project
文件夹,并将mn.js
放入该文件夹中。
现在更新
app = Flask(__name__, static_folder='script', template_folder='template')
有关Flask中静态文件的更多详细信息,您可以查看http://flask.pocoo.org/docs/0.12/quickstart/#static-files