1👍
✅
I don’t think you need a custom handler404
view here. Django’s page_not_found
view does what you want.
In Django 1.9+, you can include {{ exception }}
in the 404 template.
In your view, you could set the message when raising the exception, for example:
from django.http import Http404
def my_view(request):
raise Http404('custom error message')
It doesn’t make sense to set response.status_code
in the handler – if it’s handler404, then the status code should always be 404.
Source:stackexchange.com