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

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

handler404 not working?

I've read the docs associated with this video: https://teamtreehouse.com/library/django-basics/django-templates/ordering-and-404s

I have also read much about handler404 on StackOverflow but I couldn't make it work.

I know that I can create a 404.html page and place it under the root templates directory of my Django project, but I am trying to figure out how to make it through handler404.

So, this is what I've done:

urls.py (under my project's stub):

from fjango.conf.urls import handler404

from . import views

# This line causes so many errors, so I replaced it with
# handler = 'myapp.views.myview' but this hasn't run my view at all
handler('myapp.views.myview')

settings.py:

DEBUG = False
ALLOWED_HOSTS = ['localhost', '127.0.0.1',]

views.py:

from django.http import HttpResponse
def myview(request):
    return HttpResponse('My error msg', status=404) # I also tried HttpResponseNotFound

However, when I run the server, I can't see my HttpResponse.

I am using Django 2.0. Can you please help?