Skip to content

Instantly share code, notes, and snippets.

@dherbst
Created October 14, 2011 02:28
Show Gist options
  • Save dherbst/1286104 to your computer and use it in GitHub Desktop.
Save dherbst/1286104 to your computer and use it in GitHub Desktop.
Django Status Code Middleware
class StatusCodeMiddleware(object):
'''
Returns the status_code.html file for the response.
'''
def process_response(self, request, response):
status_code = getattr(response, 'status_code', None)
if status_code and status_code >= 400:
template = u'%s.html' % status_code
try:
response = render_to_response(
template,
{'content':response.content},
context_instance=RequestContext(request))
response.status_code = status_code
except TemplateDoesNotExist:
pass
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment