Javascript 在RESTAPI呈现的html文件中包含脚本源
我正试图通过使用Flask的REST调用呈现一个非常简单的html文件来完成前端的第一步 文件夹结构如下所示:Javascript 在RESTAPI呈现的html文件中包含脚本源,javascript,python,html,rest,flask,Javascript,Python,Html,Rest,Flask,我正试图通过使用Flask的REST调用呈现一个非常简单的html文件来完成前端的第一步 文件夹结构如下所示: > API > templates * index.html * script.js rest_api.py 在rest_api.py中,我们只有: @app.route("/") def home(): return render_template('index.html') if __name__ == '_
> API
> templates
* index.html
* script.js
rest_api.py
在rest_api.py中,我们只有:
@app.route("/")
def home():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
这里省略了导入和类似的内容
而index.html的代码如下所示:
<html>
<head>
<title>HTML</title>
<style>
body {
color : red;
font-weight: bolder;
}
</style>
</head>
<body>
<h1>First html file</h1>
<p>Some words</p>
<button id = "color">Change color!</button>
<script src="/script.js" type="text/javascript"></script>
</body>
</html>
HTML
身体{
颜色:红色;
字体大小:粗体;
}
第一个html文件
一些词
换颜色!
但是,web服务从未找到脚本文件:
127.0.0.1/:20 GET net::ERR_中止404(未找到)
我甚至尝试用js文件的完整路径更改脚本src,但都没有用:html页面完全呈现,但js文件不会被导入