0Pricing
Flask Academy · Lesson

Register errorhandler Functions

Customize responses for 404 and 500.

Beyond the Default Page

Flask shows a plain error page out of the box. You can replace it by registering your own errorhandler for any status code.

The errorhandler Decorator

You attach a function to a code with a decorator. This handler runs whenever that error happens anywhere in your app.

@app.errorhandler(404)
def not_found(e):
    return "Nothing here", 404

All lessons in this course

  1. abort and HTTP Error Codes
  2. Register errorhandler Functions
  3. Raise Custom Exception Classes
  4. Uniform JSON Error Envelopes
← Back to Flask Academy