Skip to content

Instantly share code, notes, and snippets.

@code-boxx
Last active September 3, 2024 02:40
Show Gist options
  • Select an option

  • Save code-boxx/015744c17e7b7faacae8ff3eab06d0ef to your computer and use it in GitHub Desktop.

Select an option

Save code-boxx/015744c17e7b7faacae8ff3eab06d0ef to your computer and use it in GitHub Desktop.
Python Flask Image Gallery
# (A) INIT
# (A1) LOAD REQUIRED PACKAGES
import os, glob
from flask import Flask, render_template
# (A2) FLASK SETTINGS + PATH
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 IMAGES
images = []
for ext in ("jpg", "png", "gif", "webp"):
for img in glob.iglob(PATH_STATIC + "/*." + ext):
images.append(os.path.basename(img))
# images.sort()
# images.sort(reverse=True)
# (C) GALLERY PAGE
@app.route("/")
def index():
return render_template("S2A_gallery.html", images=images)
# (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
curl https://user-images.githubusercontent.com/11156244/281273850-7147f2dd-712a-4728-8c06-f5687af33230.png --ssl-no-revoke --output static/wind.jpg
curl https://user-images.githubusercontent.com/11156244/281273848-d1a7c896-1f84-4fc2-8f85-e50bb2eebc4f.png --ssl-no-revoke --output static/water.png
curl https://user-images.githubusercontent.com/11156244/281273846-fb8ff883-f221-4c82-8c3d-2856841d73a3.png --ssl-no-revoke --output static/fire.jpg
curl https://user-images.githubusercontent.com/11156244/281273838-b511b6d1-f2d2-4aa8-b259-e19344e5e634.png --ssl-no-revoke --output static/earth.jpg
virtualenv venv
call venv\Scripts\activate
pip install flask
python S1_server.py
mkdir -m 777 templates
mkdir -m 777 static
mv ./S2A_gallery.html ./templates
mv ./S2B_gallery.css ./static
mv ./S2C_gallery.js ./static
curl https://user-images.githubusercontent.com/11156244/281273850-7147f2dd-712a-4728-8c06-f5687af33230.png --ssl-no-revoke --output ./static/wind.jpg
curl https://user-images.githubusercontent.com/11156244/281273848-d1a7c896-1f84-4fc2-8f85-e50bb2eebc4f.png --ssl-no-revoke --output ./static/water.png
curl https://user-images.githubusercontent.com/11156244/281273846-fb8ff883-f221-4c82-8c3d-2856841d73a3.png --ssl-no-revoke --output ./static/fire.jpg
curl https://user-images.githubusercontent.com/11156244/281273838-b511b6d1-f2d2-4aa8-b259-e19344e5e634.png --ssl-no-revoke --output ./static/earth.jpg
virtualenv venv
source "venv/bin/activate"
pip install flask
python S1_server.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment