Create 404 catch-all page

This commit is contained in:
Xevion
2022-03-27 00:23:03 -05:00
parent 997b1992ce
commit 1abf959645
2 changed files with 25 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
from flask import Flask from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager from flask_login import LoginManager
@@ -31,6 +31,11 @@ def create_app():
from .routes import blueprint as routes_blueprint from .routes import blueprint as routes_blueprint
app.register_blueprint(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 # CLI commands setup
@app.shell_context_processor @app.shell_context_processor
def shell_context(): def shell_context():

19
templates/errors/404.html Normal file
View File

@@ -0,0 +1,19 @@
{% extends 'layouts/index.html' %}
{% block content %}
<div class="content-inner" style="display: flex">
<div style="margin: 0 auto;">
<h2>404 - Content Not Found</h2>
<p>
{% if current_user.is_authenticated %}
Sorry <strong>{{ current_user.username }}</strong>, the
{% else %}
The
{% endif %} content you requested could not be found.
<br>
It may have been deleted or moved somewhere else.
<span style="text-align: center">Go <a href="{{ url_for('main.index') }}">home?</a></span>
</p>
</div>
</div>
{% endblock %}