On 10/02/11 15:15, vamsy krishna wrote: > Hi, > > I've defined the following in my root urls and also defined the > corresponding views and templates. The 404 handler picks up the > template correctly but the 500 handler doesn't. The control never > reaches the view function though apache logs report it as 500 server > error. Am I missing something here? > > handler500 = 'error.views.display500' > handler404 = 'error.views.display404' >
That depends on what's causing the error (and whether you have debug enabled, but you've presumably worked that bit out). For some server errors that happen before django ever gets called or very early on - in your .wsgi file, various import errors - then django's dispatcher itself simply isn't the one doing the handling yet, so it's in no position to call a custom error view (N.B. it helps to have a visibly different apache-level and django-level 500 error page, don't try to make them look exactly the same, put at least one difference in, helps to determine if something's getting as far as django before messing up). Anyway, if you want you can take a close look at to flow of control in BaseHandler.get_response() and .handle_uncaught_exception() [1] - that's what django is really doing, at least if the request gets that far! Subclassing to make your own Handler, instead of or in addition to defining a handler500 and exception middleware, allows you to take more control of the exception handling process, though is of course more involved and boilerplatey, and presumably rather more brittle in the face of changes to django too. (For our project we wanted different exception handling for (ajax, nonajax) * (debug, nondebug) requests, so subclassing a Handler seemed cleaner than monkey patching, and exception middlewares, which are only around the inner call to the view as you can see in [1], can't catch common resolver-level errors). [1] http://code.djangoproject.com/browser/django/trunk/django/core/handlers/base.py -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.