Login

Expose the 404/500 views during development

Author:
andi
Posted:
August 13, 2008
Language:
Python
Version:
.96
Score:
-4 (after 6 ratings)

A simple addition for the urls.py that exposes the 404/500 templates during development. This way you can test how those look. They're mounted under /404/ and /505/ respectively.

Add this at the bottom of your main urls.py.

1
2
3
4
5
6
7
# serve media in development mode and expose the 400/500 docs for testing
if settings.DEVELOPMENT_MODE:
    urlpatterns += patterns('', 
        url(r"%s(?P<path>.*)$" % settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
        url(r'^500/$', 'django.views.generic.simple.direct_to_template', {'template': '500.html'}),
        url(r'^404/$', 'django.views.generic.simple.direct_to_template', {'template': '404.html'}),
    )

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 2 weeks ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 10 months, 1 week ago
  5. Help text hyperlinks by sa2812 11 months ago

Comments

carljm (on August 13, 2008):

This doesn't really work for the 500 template. In testing with this urlconf, your 500 template will be rendered with context from all your context processors. In a real 500 error, Django does not make that context available and your 500 template could look very different (if, say, you depend on media_url to get media).

And generating a real 404 is never very hard to do.

#

Please login first before commenting.