simao simao - 1 year ago 146
Python Question

How to obtain a plain text Django error page

During development, I am running Django in Debug mode and I am posting data to my application using a text mode application. Ideally, I need to receive a plain text response when I get an http error code 500 so I don't have to look for the real error inside all that HTML and Javascript.

Is it possible to obtain a Django 500 Internal Server Error as plain text?

Answer Source

I think to write a middleware, because otherwise the exception isn't available in the 500.html

class ProcessExceptionMiddleware(object):
    def process_exception(self, request, exception):
        t = Template("500 Error: {{ exception }}")
        response_html = t.render(Context({'exception' : exception }))

        response = http.HttpResponse(response_html)
        response.status_code = 500
        return response
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download