views:

296

answers:

3

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.

+2  A: 

Are both debug settings false?

settings.DEBUG = False
settings.TEMPLATE_DEBUG = False
maersu
yes they are...
lud0h
Are you sure you don't have multiple settings files that may override one another?
hora
I was mistaken about multiple settings and I still get the template debug message.
lud0h
+3  A: 

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

shanyu
Perfect. Answers my question about testing my 500 (as well as 404). Thx.
lud0h
A: 

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'}),
    )
ehc