Skip to main content

Custom error pages in Flask

You can customise the error pages by adding a few instances of app.error_handler, for example:

@app.errorhandler(404)
def not_found(e: Exception) -> str:
    return render_template("not_found.html"), 404


@app.errorhandler(500)
def internal_server_error(e: Exception) -> str:
    return render_template("internal_server_error.html"), 500

Some notes: