【发布时间】:2019-09-19 20:29:48
【问题描述】:
我正在尝试使用 Flask 提供静态 mp3 文件,因此我可以将这些 mp3 文件嵌入 HTML 音频块中。我似乎在正确设置路径时遇到了问题,但我不完全确定我的问题是在我的 python 还是 html 中。
我的项目大纲:
music
app.py
static
button.js
MDF.mp3
templates
button.html
我在 app.py 中的应用初始化看起来像
app = Flask(__name__, static_url_path="", static_folder="static")
app.py 中的路由是这样的
@app.route("/<path:filename>")
def upload1():
return send_static_file("MDF.mp3")
我的默认路线:
@app.route("/", methods=["GET"])
def home():
return render_template("button.html", title="Music Box", name="MyName", song1=songList[0], song2=songList[1], song3=songList[2])
我的 button.html 看起来像
<!DOCTYPE html>
<html lang=en-US xml: lang"en-US">
<body>
<o1>
<li> {{song1}}</li>
<audio controls>
src=upload1():
Your browser does not support the <code>audio</code> element.
</audio>
<li> {{song2}}</li>
<audio controls>
src=upload2():
Your browser does not support the <code>audio</code> element.
<li> {{song3}}</li>
<audio controls>
src=upload3():
Your browser does not support the <code>audio</code> element.
</ol>
<script src="/static/button.js"></script>
</body>
</html>
我得到的错误代码是
10.245.81.226 - - [01/May/2019 04:25:08] "GET / HTTP/1.1" 404 -
10.245.81.226 - - [01/May/2019 04:25:08] "GET /static/button.js HTTP/1.1" 404 -
10.245.81.226 - - [01/May/2019 04:25:08] "GET /favicon.ico HTTP/1.1" 404 -
【问题讨论】:
-
您遇到错误了吗?如果是这样,请包括完整的堆栈跟踪。
-
@SuperShoot 我已将我的错误代码添加到原始帖子中。