的Django 500.html模板不用于内部服务器错误在Amazon Elastic青苗

问题描述:

为什么Django是不是用我的500.html模板服务器错误,我不明白。 我部署了我的魔豆弹性的应用程序,同时所有404个请求都由404.html模板处理,500错误显示标准Apache的错误:的Django 500.html模板不用于内部服务器错误在Amazon Elastic青苗

Internal Server Error 

The server encountered an internal error or misconfiguration and was unable to complete your request. 

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error. 

More information about this error may be available in the server error log. 

Apache/2.2.25 (Amazon) Server at myapp.elasticbeanstalk.com Port 80 

可能是什么? (我有在同一个地方既模板)

+0

是否所有的500错误显示这些错误,即使你故意造成的呢?或者这可能是一个特定的错误? – tutuDajuju

+0

嗯...好问题...实际上是错误由未处理的异常DoesNotExist造成的......所以,在我看来,必须由框架使用500.html模板 – daveoncode

+1

请检查是否办理一个简单的错误情况[DEBUG_PROPAGATE_EXCEPTIONS](https://docs.djangoproject.com/en/dev/ref/settings/#debug-propagate-exceptions)被设置。另外,请看看日志,apache和django的 – tutuDajuju

我有一个类似的问题,一旦因为我是用我的500.html模板上下文变量。但默认情况下,Django不会向500错误页面提供任何上下文。所以这会导致出现“双重”错误,其中呈现错误页面本身会产生错误。

从Django文档:

The default 500 view passes no variables to the 500.html template and is rendered with an empty Context to lessen the chance of additional errors.

https://docs.djangoproject.com/en/dev/topics/http/views/#the-500-server-error-view

所以,如果你在你的500错误页面使用任何的环境变量,这可能是发生了什么事。不知道这是否有助于但在你的情况......

如果是这样的问题,解决办法是写一个自定义错误处理视图以最少的背景下呈现静态文件等(如上面的文档中描述) 。

+0

你将成为我最好的书呆子朋友! :d – daveoncode