Issue
I'm using flask to manage my website, I'm trying to includes a simple 404 page error, but I keep getting the plain one from flask. Here is my code:
flask app
@views.errorhandler(404)
def page_not_found(e):
return render_template('errors/404.html'), 404
html
{% with title="404 Not Found" %}
{% include "head.html" %}
{% endwith %}
<body>
<h1>404 Page not found</h1>
</body>
</html> ### I need to include the </html> tag because it's in the head.
However I'm getting this:
Solution
Since you have registered the error handler with views
, I presume you are working with blueprints. If this assumption is correct, please note the last paragraph in the "Handling" section:
Handlers registered on the blueprint take precedence over those registered globally on the application, assuming a blueprint is handling the request that raises the exception. However, the blueprint cannot handle 404 routing errors because the 404 occurs at the routing level before the blueprint can be determined.
To achieve the desired behaviour, register this error handler with the "app" returned by the Flask(__name__)
initialization.
Answered By - Magnun Leno
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.