From 1abf95964572433cbe4f62c46fe38f973bfd75af Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 27 Mar 2022 00:23:03 -0500 Subject: [PATCH] Create 404 catch-all page --- create_app.py | 7 ++++++- templates/errors/404.html | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 templates/errors/404.html diff --git a/create_app.py b/create_app.py index 51e8ade..5926c8e 100644 --- a/create_app.py +++ b/create_app.py @@ -1,4 +1,4 @@ -from flask import Flask +from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager @@ -31,6 +31,11 @@ def create_app(): from .routes import blueprint as routes_blueprint app.register_blueprint(routes_blueprint) + @app.errorhandler(404) + def page_not_found(e): + # note that we set the 404 status explicitly + return render_template('errors/404.html'), 404 + # CLI commands setup @app.shell_context_processor def shell_context(): diff --git a/templates/errors/404.html b/templates/errors/404.html new file mode 100644 index 0000000..8a0e94e --- /dev/null +++ b/templates/errors/404.html @@ -0,0 +1,19 @@ +{% extends 'layouts/index.html' %} + +{% block content %} +
+
+

404 - Content Not Found

+

+ {% if current_user.is_authenticated %} + Sorry {{ current_user.username }}, the + {% else %} + The + {% endif %} content you requested could not be found. +
+ It may have been deleted or moved somewhere else. + Go home? +

+
+
+{% endblock %}