Воспроизведение видео в шаблоне Flask
Если у вас есть видеофайлы в папке static
, вы можете обращаться к ним в шаблонах, используя url_for
, как и другие статические файлы. Документацию по обслуживанию статических файлов можно найти в этом 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>
Выход: