Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I make an error handler with flask

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?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading