Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Flask Error page

from flask import Flask
app = Flask(__name__)

@app.route("/")
def main():
    return '''
Main
<a href="/bad">bad</a>
'''

@app.route("/bad")
def bad():
    raise Exception("This is a bad page")
    return 'Bad page'

Will not trigger in debug mode!

$ FLASK_APP=echo.py FLASK_DEBUG=0  flask run
curl -I http://localhost:5000/not

HTTP/1.0 500 INTERNAL SERVER ERROR
from flask import Flask
app = Flask(__name__)

@app.route("/")
def main():
    return '''
Main
<a href="/bad">bad</a>
'''

@app.route("/bad")
def bad():
    raise Exception("This is a bad page")
    return 'Bad page'

@app.errorhandler(500)
def not_found(err):
    #raise Exception("Oups")
    return "Our Page crashed", 500