Home > Software design >  How do I make an error handler with flask
How do I make an error handler with flask

Time:05-27

I am creating a web application and I would like to do a styled 404 page not found if someone tries to enter one of my routes that is not created. Is there a way I can do this?

CodePudding user response:

welcome to stackoverflow!

To create a error handler of any error code in flask you must do the following, for my example I will use a 404 error as requested in the post:

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

If you want to error handle a 505 just substitut the 404 for a 505 and create a new html file in templates

  • Related