如何获取纯文本Django错误页面 [英] How to obtain a plain text Django error page

查看:142
本文介绍了如何获取纯文本Django错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发过程中,我正在调试模式下运行Django,并且使用文本模式应用程序将数据发布到我的应用程序。理想情况下,当我得到一个http错误代码500时,我需要收到一个纯文本响应,所以我不必在所有HTML和Javascript中查找真正的错误。

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.

是否可以以纯文本形式获取Django 500内部服务器错误?

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

推荐答案

我想写一个中间件,因为否则在500.html

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

http://docs.djangoproject.com/en/dev/topics/http/middleware/#process-exception

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

这篇关于如何获取纯文本Django错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆