diff --git a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/app.py b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/app.py index d45a183..daa7b88 100644 --- a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/app.py +++ b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/app.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -from flask import Flask +'''The app module, containing the app factory function.''' +from flask import Flask, render_template from flask_debugtoolbar import DebugToolbarExtension from {{cookiecutter.repo_name}}.settings import ProdConfig @@ -19,6 +20,7 @@ def create_app(config_object=ProdConfig): app.config.from_object(config_object) register_extensions(app) register_blueprints(app) + register_errorhandlers(app) return app @@ -36,3 +38,11 @@ def register_blueprints(app): app.register_blueprint(public.views.blueprint) app.register_blueprint(user.views.blueprint) return None + + +def register_errorhandlers(app): + def render_error(error): + return render_template("{0}.html".format(error.code)), error.code + for errcode in [401, 404, 500]: + app.errorhandler(errcode)(render_error) + return None diff --git a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/templates/401.html b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/templates/401.html new file mode 100644 index 0000000..3f45f7f --- /dev/null +++ b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/templates/401.html @@ -0,0 +1,16 @@ +{% raw %} +{% extends "_layouts/base.html" %} + +{% block page_title %}Unauthorized{% endblock %} + +{% block content %} +
You are not authorized to see this page. Please log in or + create a new account. +
+Sorry, that page doesn't exist.
-Want to go home instead?
+Sorry, something went wrong on our system. Don't panic, we are fixing it! Please try again later.
+