Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Django Templates Ordering and 404s

Dillon Reyna
Dillon Reyna
9,531 Points

Custom 404 Page?

Hey!

Let's say I wanted to set a custom 404 page, instead of using the stock option from Django.

Where would I write the HTML for this?

Would I create a 'view' for this? If so, where?

How do I set my site to default to this new 404 page instead of the old one?

2 Answers

Haydar Al-Rikabi
Haydar Al-Rikabi
5,971 Points

The easiest way would be to place a "404.html" file inside the project-wide templates directory which you can find in "settings.py". You should look for "Templates" and then "DIRS".

You can edit the 404.html to your liking.

Hasan Ahmad
Hasan Ahmad
6,727 Points

im guessing you would go to the url for your app and then make a variable called handler404, there is more in the django docs: https://docs.djangoproject.com/en/1.8/topics/http/views/#customizing-error-views