我有一个flask应用程序,它应该播放一个视频时,页面加载,但它只是显示在左上角,没有改变,从视频的第一帧
我已经试过将它插入html代码中,但不起作用
{% extends "base.html" %}
{% block content %}
<video height="224" width="400" preload="auto" data-video-width="400" src="../static/chugging.mp4" style="margin-right: auto; margin-left: auto; align-items: center"></video>
{% endblock %}我希望看到它播放,或者至少看到一个播放按钮,但它只是左上角的一个小框架。
发布于 2019-05-03 12:24:43
在Flask模板中播放视频
如果static文件夹中有视频文件,则可以像访问其他静态文件一样,使用url_for在模板中访问它们。提供静态文件的文档可以在in this URL中找到。
在这里我展示了一个在模板中播放视频文件的例子。
目录结构:
├── app.py
├── static
│ └── demo.mp4
└── templates
└── index.htmlapp.py
from flask import Flask, render_template
app = Flask(__name__, static_folder='static')
@app.route('/')
def index():
return render_template('index.html')index.html
<!DOCTYPE html>
<html>
<head>
<title>Video Example</title>
</head>
<body>
<h2>Serving video files from Flask template</h2>
<video width="320" height="240" controls>
<source src={{ url_for('static', filename="demo.mp4") }} type="video/mp4">
Your browser does not support the video tag.
</video>
</body>
</html>输出:

发布于 2021-05-11 22:58:35
if __name__=='__main__':
app.run(debug=True)完成上面给出的所有操作后,只需在end...It处的.py文件中添加以下行即可完成任务
https://stackoverflow.com/questions/55961665
复制相似问题