From 48942f9e4a3f02f458b2032901a0f1d298cd961e Mon Sep 17 00:00:00 2001 From: Ilya Patrzykat-Hannas <54457854+patrzykat@users.noreply.github.com> Date: Mon, 3 May 2021 02:29:46 -0300 Subject: [PATCH] Initializing flash messages and adding url_for() in templates (#9) * adding url_for to prevent errors when changing routes * Update layout.html * Update app.py --- app.py | 4 ++-- templates/layout.html | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 18f8197..41aa279 100644 --- a/app.py +++ b/app.py @@ -108,12 +108,12 @@ def FUN_upload_image(): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: - flash('No file part') + flash('No file part', category='danger') return(redirect(url_for("FUN_private"))) file = request.files['file'] # if user does not select file, browser also submit a empty part without filename if file.filename == '': - flash('No selected file') + flash('No selected file', category='danger') return(redirect(url_for("FUN_private"))) if file and allowed_file(file.filename): filename = secure_filename(file.filename) diff --git a/templates/layout.html b/templates/layout.html index 6a14379..fb6c5bf 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -19,13 +19,13 @@
+{% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} +