From f0fb5f0d9fa7e06e49f8c46d590fd3bc355c3c3d Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 3 Nov 2018 13:21:26 +0100 Subject: [PATCH] Serve images from a separate direcory configured in an external config file (config.py) --- .gitignore | 1 + config.py | 1 + slider.py | 9 ++++++++- templates/hello.html | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 config.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/config.py b/config.py new file mode 100644 index 0000000..0b692c8 --- /dev/null +++ b/config.py @@ -0,0 +1 @@ +imgdir = "/home/mandlm/Foto Export/2018/09/2018-09-03" diff --git a/slider.py b/slider.py index db343c8..a695783 100755 --- a/slider.py +++ b/slider.py @@ -1,8 +1,10 @@ #!/usr/bin/python3 -from flask import Flask, render_template +from flask import Flask, render_template, send_from_directory from random import randint +import config + app = Flask(__name__) @@ -11,5 +13,10 @@ def hello(): return render_template("hello.html", num=randint(1, 23)) +@app.route("/img/") +def image(filename): + return send_from_directory(config.imgdir, filename) + + if __name__ == "__main__": app.run() diff --git a/templates/hello.html b/templates/hello.html index 77172c2..1a0f266 100644 --- a/templates/hello.html +++ b/templates/hello.html @@ -2,5 +2,6 @@

Hello slider number {{ num }}!

+

Image