Flask giving an internal server error instead of rendering 404


Question

In my Flask app, I set up a 404 handler like this:

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

However, when a user goes to an unrecognized URL, the system gives an internal server error instead of rendering my 404 template. Am I missing something?

1
7
7/9/2019 5:17:23 PM

Internal Server Error is HTTP error 500 rather than 404 and you haven't added error handler for it. This occurs when the server is unable to fulfill the client request properly. To add a gracious message when such error occurred, you can add a errorhandler like 404.

@app.errorhandler(500)
def exception_handler(e):
    return render_template('500.html'), 500
7
2/9/2012 3:07:22 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon