When a user opens a post that does not exist, or visits the admin area without permission, the view must stop immediately and return the correct error code — not render an error template by hand and return it with status 200. Flask ships with abort() : it raises an HTTP exception, stops the view right there, and Flask returns the right status code with an error page. Combined with errorhandler() , you get a clean, standard error page for the whole application.
The Problem
The most common approach is to return an error string with a status code by hand: return "Post not found", 404 . It works, but every view repeats the same pattern, and it is easy to forget the status code — leave out , 404 and the error page returns 200, so Google indexes your “not found” page and clients or APIs cannot tell the request failed.…