class ProcessExceptionMiddleware(object):

    def process_exception(self, request, exception):
        t = Template('500 Error: {{ exception }}')
response_html = t.render(Context({'exception': exception}))
How to obtain a plain text Django error page