如何获取纯文本Django错误页面
在开发过程中,我以Debug模式运行Django,并使用文本模式应用程序将数据发布到我的应用程序中。理想情况下,当我收到http错误代码500时,我需要接收纯文本响应,因此我不必在所有HTML和Javascript中寻找真正的错误。
是否可以获取纯文本的Django 500 Internal Server Error?
-
我想写一个中间件,因为否则该异常在500.html中不可用
http://docs.djangoproject.com/en/dev/topics/http/middleware/#process-
exceptionclass 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