Created
October 14, 2011 02:28
-
-
Save dherbst/1286104 to your computer and use it in GitHub Desktop.
Django Status Code Middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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