How to make a default 404 page in Flask

How to make a default 404 page in Flask

There is many benefits in having a default 404 page. You keep your visitors on the website and is able display a link so they can do something else on your website, beside having to deal with the standard dead end 404 page that the browser generates.

05-02-2023 |

Python
Errors
Flask

To add a default 404 page in flask with Python, you need to create an errorhandler where your routes is and give it the error code as parameter. In this case it is 404.

Finally you need to create the actual 404 page that you want to return. So inside your templates folder, create a new file called 404.html

To test it, just run your application and then type a url that does not exist on your website. You should then get the 404.html in return.


Like what you see?


New C# Learning Area - Free!

Our website now offers a new section on C# theory, including code examples and related video tutorials.

ZetBit

Subscribe to ZetBits Newsletter