开发者

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 s开发者_开发问答ame with the 404.html and this one just works fine.

Has anyone an idea what the problem could be?


  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


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.


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})))


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜