Kolan
Kolan

Reputation: 21

Django's 500.html doesn't work

I want to use my own page for 500 errors. So I've put a 500.html in my templates root directory. But when an error occurs the default apache 500 page is displayed. I did the same with the 404.html and this one just works fine.

Has anyone an idea what the problem could be?

Upvotes: 2

Views: 985

Answers (5)

Edd
Edd

Reputation: 1032

My problem was that I was trying to extend another template which contained a bunch of context and configuration variables in it so, the error template itself was causing a Server Error. Steve Jalim and OBu answers helped.

Upvotes: 0

OBu
OBu

Reputation: 5177

I ran into the same problem today and the prolem was in my 500.html-file: I contained a German Umlaut ("ö") and this one resulted in apache throwing it's own error message while rendering my 500 error message. You can recognize that by looking at your apache error log and in my case it showed a UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 583: invalid start byte.

In fact the answer of stevejalim was helpful in figuring this out.

Upvotes: 1

Ricardo Carmo
Ricardo Carmo

Reputation: 703

Change the return value from def server_error in django.views.defaults:

from:

return http.HttpResponseServerError(t.render(Context({})))

to:

return http.HttpResponseServerError(t.render(RequestContext(request, {'request_path': request.path})))

Upvotes: 1

rob
rob

Reputation: 37644

By default, django add from django.conf.urls.defaults import * to your urls.py.
Static analysis tools may complain about it, but if you change it to import only the names you really use (e.g. patterns and include) you will end up breaking the mechanism Django uses to handle errors - and for instance it will not display 500 errors.

Upvotes: 1

Steve Jalim
Steve Jalim

Reputation: 12195

  1. Check that the 500 is definitely being thrown by Django and not actually by Apache, before Django gets a look-in. Where, according to the Apache error log, is the 500's root cause?

  2. Check the file permissions on that 500 page (unlikely to be wrong, but still)

  3. DPaste your 500.html page for us to see if there's anything more complex in it than straight HTML

Upvotes: 2

Related Questions