Handle empty input folders
This commit is contained in:
parent
6deefc7ea8
commit
d5f6b4bfd7
@ -26,6 +26,7 @@ def random():
|
||||
|
||||
@app.route("/random_image/")
|
||||
def random_image():
|
||||
try:
|
||||
last_modified_time, last_modified_file = max(
|
||||
(f.stat().st_mtime, f) for f in imgdir.glob(img_glob)
|
||||
)
|
||||
@ -35,6 +36,8 @@ def random_image():
|
||||
else:
|
||||
images = list(imgdir.glob(img_glob))
|
||||
selected_image = choice(images).relative_to(imgdir)
|
||||
except ValueError:
|
||||
return redirect(url_for("static", filename="clear.gif"))
|
||||
|
||||
return redirect(
|
||||
url_for("image", filename=selected_image)
|
||||
|
Reference in New Issue
Block a user