I would like to know if it's possible to loop only a specific files like video/mp4? In the folder I have also multiple files and sub-foldes and the html load every elements.
{% for file in video_files %}
<video controls width="250" height="250">
<source src={{ url_for('static', filename=file) }} type="video/mp4">
</video>
{% endfor %}
This is the code.
Python with Flask
from flask import Flask, render_template
import sys
app = Flask(__name__, static_folder='static')
import os
path = 'static'
@app.route('/')
def index():
files = []
# r=root, d=directories, f = files
for r,d,f in os.walk(path):
for file in f:
files.append(file)
video_files = files
return render_template('index.html', video_files=video_files)
if __name__ == '__main__':
app.run(host='localhost', debug=True, threaded=True)