【问题标题】:Django 500.html template not used for internal server error on Amazon Elastic BeanstalkDjango 500.html 模板未用于 Amazon Elastic Beanstalk 上的内部服务器错误
【发布时间】:2014-03-25 07:53:16
【问题描述】:

我不明白为什么 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

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

【问题讨论】:

  • 是否所有 500 个错误都显示了这些错误,即使是您故意创建的错误?或者这可能是一个特定的错误?
  • mmm...好问题...实际上该错误是由未处理的DoesNotExist异常引起的...因此,在我看来,这是一个简单的错误情况,必须由使用500的框架处理.html 模板
  • 请检查是否设置了 [DEBUG_PROPAGATE_EXCEPTIONS] (docs.djangoproject.com/en/dev/ref/settings/…)。另外,请查看 apache 和 django 的日志

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


【解决方案1】:

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

来自 Django 文档:

默认的 500 视图不向 500.html 模板传递变量,并且 使用空上下文呈现以减少额外的机会 错误。

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

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

如果这是问题所在,解决方案将是编写一个自定义错误处理视图,并使用最少的上下文来呈现静态文件等(如上面的文档中所述)。

【讨论】:

  • 你将成为我最好的书呆子朋友! :D
猜你喜欢
  • 1970-01-01
  • 2020-02-20
  • 2016-03-07
  • 1970-01-01
  • 2019-11-27
  • 1970-01-01
  • 2018-11-01
  • 2015-06-25
  • 2015-10-10
相关资源
最近更新 更多