0

I am trying to get custom error pages (404 & 500) to work in my Django application.

So far I have the following:

urls.py

handler404 = views.error_404
handle500 = views.error_500

views.py

def error_500(request, exception):
    return render(request, '500.html', status=500)

def error_404(request, exception):
    return render(request, '404.html', status=404)

DEBUG is set to FALSE.

However when I try access an error page I get the following error:

"A server error occurred. Please contact the administrator."

Which (obviously) is not my error template.

Any help appreciated!

Rno
  • 5
  • 3

1 Answers1

0

You have a typo in your urls.py file. Use:

handler500 = views.error_500

Instead of:

handle500 = views.error_500

Here is the Django docs link for more detail. PS: You can also pass the path of your custom view as a string like this.

handler500 = "your_app.views.error_500"

This is just a matter of preference.

Mubashar Javed
  • 1,197
  • 1
  • 9
  • 17