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

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.


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


In Django 1.6 django.views.generic.simple.direct_to_template does not exists anymore, these are my settings for special views:

# urls.py

from django.views.generic import TemplateView
from django.views.defaults import page_not_found, server_error

urlpatterns += [
    url(r'^400/$', TemplateView.as_view(template_name='400.html')),
    url(r'^403/$', TemplateView.as_view(template_name='403.html')),
    url(r'^404/$', page_not_found),
    url(r'^500/$', server_error),
]

And if you want to use the default Django 500 view instead of your custom view:

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

Continuing shanyu's answer, in Django 1.3+ use:

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^500/$', 'django.views.defaults.server_error'),
        (r'^404/$', 'django.views.defaults.page_not_found'),
    )

Are both debug settings false?

settings.DEBUG = False
settings.TEMPLATE_DEBUG = False