From 5031b1e8a2094477768114fbad1350dd78b60f1d Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 5 Nov 2018 21:57:26 +0100 Subject: [PATCH 1/2] Serve random images with automatic refresh --- slider.py | 10 +++++----- templates/hello.html | 8 -------- templates/random.html | 8 ++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 templates/hello.html create mode 100644 templates/random.html diff --git a/slider.py b/slider.py index 62456c3..f4f8bcf 100755 --- a/slider.py +++ b/slider.py @@ -3,7 +3,7 @@ from flask import Flask, render_template, send_from_directory, redirect, url_for from random import randint from os import listdir -import random +from random import choice import config @@ -11,13 +11,13 @@ app = Flask(__name__) @app.route("/") -def hello(): - return render_template("hello.html", num=randint(1, 23)) +def random(): + return render_template("random.html") -@app.route("/random_image") +@app.route("/random_image/") def random_image(): - filename = random.choice(listdir(config.imgdir)) + filename = choice(listdir(config.imgdir)) return redirect(url_for("image", filename=filename)) diff --git a/templates/hello.html b/templates/hello.html deleted file mode 100644 index 49add83..0000000 --- a/templates/hello.html +++ /dev/null @@ -1,8 +0,0 @@ - - -

Hello slider number {{ num }}!

-

-

Image

-

Random Image

- - diff --git a/templates/random.html b/templates/random.html new file mode 100644 index 0000000..1e3837f --- /dev/null +++ b/templates/random.html @@ -0,0 +1,8 @@ + + + + + + + + From 0f07fb70c8aae673b73ed069c54640baa74fd93b Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 5 Nov 2018 22:01:57 +0100 Subject: [PATCH 2/2] Configure refresh via config file --- config.py | 1 + slider.py | 2 +- templates/random.html | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 533ba28..ced3d85 100644 --- a/config.py +++ b/config.py @@ -1 +1,2 @@ imgdir = "." +refresh = 5 diff --git a/slider.py b/slider.py index f4f8bcf..9b0259e 100755 --- a/slider.py +++ b/slider.py @@ -12,7 +12,7 @@ app = Flask(__name__) @app.route("/") def random(): - return render_template("random.html") + return render_template("random.html", refresh=config.refresh) @app.route("/random_image/") diff --git a/templates/random.html b/templates/random.html index 1e3837f..4050ccb 100644 --- a/templates/random.html +++ b/templates/random.html @@ -1,6 +1,6 @@ - +