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 %} +
+ {% 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?
+