How to test 500.html error page in django development env?

lud0h picture lud0h · Apr 29, 2010 · Viewed 15.3k times · Source

I am using Django for a project and is already in production.

In the production environment 500.html is rendered whenever a server error occurs.

How do I test the rendering of 500.html in dev environment? Or how do I render 500.html in dev, if I turn-off debug I still get the errors and not 500.html

background: I include some page elements based on a page and some are missing when 500.html is called and want to debug it in dev environment.

Answer

shanyu picture shanyu · Apr 30, 2010

I prefer not to turn DEBUG off. Instead I put the following snippet in the urls.py:

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^500/$', 'your_custom_view_if_you_wrote_one'),
        (r'^404/$', 'django.views.generic.simple.direct_to_template', {'template': '404.html'}),
    )

In the snippet above, the error page uses a custom view, you can easily replace it with Django's direct_to_template view though.

Now you can test 500 and 404 pages by calling their urls: http://example.com/500 and http://example.com/404