Add error handlers and templates for 401, 404, and 500

master
Steven Loria 11 years ago
parent 82eca9190d
commit 0a2412525f
  1. 12
      {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/app.py
  2. 16
      {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/templates/401.html
  3. 29
      {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/templates/404.html
  4. 14
      {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/templates/500.html

@ -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

@ -0,0 +1,16 @@
{% raw %}
{% extends "_layouts/base.html" %}
{% block page_title %}Unauthorized{% endblock %}
{% block content %}
<div class="jumbotron">
<div class="text-center">
<h1>401</h1>
<p>You are not authorized to see this page. Please <a href="{{ url_for('public.home')}}">log in</a> or
<a href="{{ url_for('public.register') }}">create a new account</a>.
</p>
</div>
</div>
{% endblock %}
{% endraw %}

@ -3,28 +3,13 @@
{% block page_title %}Page Not Found{% endblock %}
{% block css %}
<style type="text/css">
body {
padding-top: 40px;
}
h1, p {
text-align: center;
}
h1 {
font-size: 64px;
margin: 75px 0 50px;
}
p {
font-size: 24px;
margin: 15px 0;
}
</style>
{% endblock %}
{% block content %}
<h1>404</h1>
<p>Sorry, that page doesn't exist.</p>
<p>Want to <a href="{{ url_for('home') }}">go home</a> instead?</p>
<div class="jumbotron">
<div class="text-center">
<h1>404</h1>
<p>Sorry, that page doesn't exist.</p>
<p>Want to <a href="{{ url_for('public.home') }}">go home</a> instead?</p>
</div>
</div>
{% endblock %}
{% endraw %}

@ -0,0 +1,14 @@
{% raw %}
{% extends "_layouts/base.html" %}
{% block page_title %}Server error{% endblock %}
{% block content %}
<div class="jumbotron">
<div class="text-center">
<h1>500</h1>
<p>Sorry, something went wrong on our system. Don't panic, we are fixing it! Please try again later.</p>
</div>
</div>
{% endblock %}
{% endraw %}
Loading…
Cancel
Save