Flask giving an internal server error instead of rendering 404

In my Flask application, I configured the 404 handler as follows:

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

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

+7
source share
3 answers

An internal server error is an HTTP 500 error, not a 404 error, and you have not added an error handler to it. This occurs when the server cannot complete the client request properly. To add a gracious message when such an error occurs, you can add an error handler, for example, 404.

 @app.errorhandler(500) def exception_handler(e): return render_template('500.html'), 500 
+7
source

This will also happen if the debug parameter is set to true. Try setting debug to false and see if your user number 404 appears.

0
source

There is probably a problem displaying the 404 template which then causes an internal server error.

I suggest checking the logs for your application.

0
source

Source: https://habr.com/ru/post/908044/


All Articles