From 2773f94b36818bee0f15925a1ab73b8e8369daac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20Ny=CC=81vlt?= Date: Mon, 21 Aug 2023 10:56:04 +0200 Subject: [PATCH] Handle article not found --- view/app.py | 8 ++++++-- view/templates/not_found.html | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 view/templates/not_found.html diff --git a/view/app.py b/view/app.py index 8ce5868..1d6f262 100644 --- a/view/app.py +++ b/view/app.py @@ -84,7 +84,7 @@ def index(): diffs = db.fetchall() html = render_template( - "./index.html", + "index.html", diffs=diffs, page=page, pagination=pagination, @@ -104,8 +104,12 @@ def article_detail(article_id: str): db = get_db().cursor() db.execute("SELECT * FROM diffs WHERE article_id = ?", (article_id,)) result = db.fetchall() + + if len(result) == 0: + return make_response(render_template("not_found.html"), 404) + article_url = result[0]["article_url"] - # TODO: Handle if nothing is found and return 404 in that case. + return render_template( "article_detail.html", article_id=article_id, diff --git a/view/templates/not_found.html b/view/templates/not_found.html new file mode 100644 index 0000000..32d02d1 --- /dev/null +++ b/view/templates/not_found.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block body %} +
+

😭

+

Nenalezeno

+
+{% endblock body %}