如何在Flask中为使用HTML的视频创建URL?

2024-05-08 03:04:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个flask服务器,里面有一个视频文件。如何使用HTML <video>标记让用户观看视频?在服务器中,我有send_file:

@app.route("/movie")
def movie():
    return send_file("Images/i0.mov")

然后,在HTML中,我有:

<video width="90" height="90" controls>
  <source src="/movie" type="video/quicktime">
  Uh oh! Your browser doesn't support the <code>video</code> tag.
</video>

但是,没有视频播放,我也没有收到Uh oh!消息。我做错了什么

这就是我得到的:

<html> <video width="90" height="90" controls> <source src="/movie" type="video/quicktime"> Uh oh! Your browser doesn't support the <code>video</code> tag. </video> <br><br> It just doesn't load! </html>

Tags: 服务器sendsource视频htmlvideocodemovie
1条回答
网友
1楼 · 发布于 2024-05-08 03:04:42

根据我的经验,send_file是从烧瓶下载一个文件。我有一个类似的例子,我将视频文件名作为变量传递

为添加url_并在HTML文件中传递该文件

<video width="800" height="450" controls>
  <source src="{{url_for('static', filename=file)}}" type="video/mp4">
</video>

以及后端

@app.route('/video/<file>')
def video(file):
    return render_template('stream.html',file=file)

相关问题 更多 >