我有一个 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 %}
我希望看到它播放或至少在某处看到播放按钮,但它只是左上角的一个小框架
在 Flask 模板中播放视频
如果您有视频文件static
您可以使用模板在模板中访问它们的文件夹url_for
就像其他静态文件一样。可以找到提供静态文件的文档在这个网址中 http://flask.pocoo.org/docs/1.0/quickstart/#static-files.
这里我展示了一个在模板中播放视频文件的示例。
目录结构:
├── app.py
├── static
│ └── demo.mp4
└── templates
└── index.html
app.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>
Output:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)