Skip to content

Instantly share code, notes, and snippets.

@code-boxx
Last active October 1, 2023 06:23
Show Gist options
  • Save code-boxx/998c2a4db4334746926e2eb49fadb08a to your computer and use it in GitHub Desktop.
Save code-boxx/998c2a4db4334746926e2eb49fadb08a to your computer and use it in GitHub Desktop.
Python Flask Video Gallery
# (A) INIT
# (A1) LOAD MODULES
import os, glob
from flask import Flask, render_template
# (A2) FLASK SETTINGS + INIT
HOST_NAME = "localhost"
HOST_PORT = 80
PATH_BASE = os.path.dirname(os.path.abspath(__file__))
PATH_STATIC = os.path.join(PATH_BASE, "static")
app = Flask(__name__)
# app.debug = True
# (B) GET ALL VIDEO FILES
videos = []
for ext in ("avi", "mp4", "webm"):
for vid in glob.iglob(PATH_STATIC + "/*." + ext):
videos.append(os.path.basename(vid))
# videos.sort()
# videos.sort(reverse=True)
# (C) GALLERY PAGE
@app.route("/")
def index():
return render_template("S2A_gallery.html", videos=videos)
# (D) START
if __name__ == "__main__":
app.run(HOST_NAME, HOST_PORT)
md templates
md static
move S2A_gallery.html templates
move S2B_gallery.css static
move S2C_gallery.js static
virtualenv venv
call venv\Scripts\activate
pip install flask
mkdir -m 777 templates
mkdir -m 777 static
mv ./S2A_gallery.html /templates
mv ./S2B_gallery.css /static
mv ./S2C_gallery.js /static
virtualenv venv
source "venv/bin/activate"
pip install flask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment