gpt4 book ai didi

python - Flask 不会在 html 中播放视频

转载 作者:行者123 更新时间:2023-12-05 00:58:53 24 4
gpt4 key购买 nike

我有一个 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 在模板中访问它们。可以找到提供静态文件的文档 in this URL .

这里我展示了一个在模板中播放视频文件的例子。

目录结构:

├── 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>

输出:

video playing in Flask template

关于python - Flask 不会在 html 中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55961665/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com