Django 500.html模板未用于Amazon Elastic Beanstalk上的内部服务器错误

时间:2014-02-23 20:58:58

标签: django amazon-web-services elastic-beanstalk

我不明白为什么django没有使用我的500.html模板来解决服务器错误。 我在Elastic Beanstalk上部署了我的应用程序,而所有404请求都由404.html模板处理,500错误显示标准的apache错误:

Internal Server Error

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

Please contact the server administrator, root@localhost 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

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

1 个答案:

答案 0 :(得分:4)

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

来自Django文档:

  

默认的500视图不会将变量传递给500.html模板和   使用空Context进行渲染,以减少额外的机会   错误。

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

因此,如果您在500错误页面中使用任何上下文变量,那可能就是发生了什么。不确定这对你的情况是否有帮助......

如果这是问题,解决方案是编写一个自定义错误处理视图,其中包含最小上下文以呈现静态文件等(如上文中所述)。