Skip to content

Instantly share code, notes, and snippets.

@dryan
Created September 7, 2009 03:11
Show Gist options
  • Save dryan/182120 to your computer and use it in GitHub Desktop.
Save dryan/182120 to your computer and use it in GitHub Desktop.
Django middleware for setting contexts in error documents
class ErrorHandler(object):
def process_response(self, request, response):
status = response.status_code
if status == 200:
return response
else:
from django.http import HttpResponse
from django.template import RequestContext, loader
try:
t = loader.get_template( u'%d.html' % status )
response = HttpResponse(t.render(RequestContext(request)), status = status)
except:
pass
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment