Flask Tutorial
About Lesson

In this Flask lesson we are going to learn How to Create Custom Error Page in Flask, so when you are going to develop a web application or website, when a user write invalid route, the user get a 404 error page , instead of 404 error page we want to show them our Custom Error Page in Flask. Flask allows an application to define Custom Error Page that can be based on our template that we have, you can define Flask Custom Error Page like regular routes.

 

 

This is our app.py file, we have created two new routes for custom error pages.

 

 

You can see that we have defined two new routes, the first one is for page_not_found() and the second one is for internal_server_error().

 

 

 

Now let’s create templates for our custom error pages, we need two new templates.

 

 

templates/404.html

 

 

templates/500.html

 

 

 

These are our other html files.

 

 

templates/base.html

 

 

templates/index.html

 

 

 

templates/contact.html

 

 

 

templates/about.html

 

 

 

Now run your application and go to a route that does not exists, http://localhost:5000/articles

How to Create Custom Error Page in Flask
How to Create Custom Error Page in Flask

 

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found