Flask不会在html

时间:2019-05-03 00:00:24

标签: python html video flask

我有一个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 %}

我希望能看到它的播放或至少看到一个播放按钮,但它只是左上角的一小帧

2 个答案:

答案 0 :(得分:0)

在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

答案 1 :(得分:-1)

if __name__=='__main__':
    app.run(debug=True)

在完成上面给出的所有操作后,只需在最后的 .py 文件中添加这些行...它就会完成任务