November 2014
Intermediate to advanced
258 pages
5h 15m
English
Every application throws errors to users at some point of time. These errors can be due to the user typing a wrong URL (404), application overload (500), or something forbidden for a certain user to access (403). A good application handles these errors in an interactive way instead of showing an ugly white page, which makes no sense to most users. Flask provides an easy-to-use decorator to handle these errors.
The Flask app object has a method called errorhandler(), which enables us to handle our application's errors in a much more beautiful and efficient manner.
Consider the following code snippet:
@app.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404 ...Read now
Unlock full access