【问题标题】:django 500.html on prodserver not showing up - instead 500 Internal Server Errorprodserver 上的 django 500.html 未显示 - 而是 500 内部服务器错误
【发布时间】:2013-10-28 06:34:06
【问题描述】:

我正在部署 django 页面,终于可以运行了,但在生产服务器中找不到 500 模板,我在var/log/apache2/error.log 中收到此错误:

raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html

我创建了 500.html 和 404.html 模板,它们位于 templates 目录下。这是我的 settings.py

import os
gettext = lambda s: s
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))

TEMPLATE_DIRS = (
    "templates",
    os.path.join(PROJECT_PATH, "templates"),
)

我错过了什么?为什么服务器找不到500.html,即使它在那里?

【问题讨论】:

  • 请在您的网站上尝试随机路径,例如“/sdfjlksjfdsd”,请告诉我发生了什么?您是否将 DEBUG=False 放入您的 settings.py 文件中?
  • @SrinivasReddyThatiparthy,是的,我输入了DEBUG=False。如果我将其更改为True,我会得到正常的错误回溯,但这不应该在产品服务器中。
  • @SrinivasReddyThatiparthy,你说的另一条路是什么意思?而不是 templates 另一条路径?
  • 我只是在模拟 404.html 功能。如果你给一些随机路径,它应该显示 404.html 对吗?试试看。让我知道 404.html 工作正常吗?
  • @SrinivasReddyThatiparthy,是的,404 正在工作。

标签: python django apache


【解决方案1】:
by getting the same issue before i simple replace like this :    

import os
TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__),'templates').replace('\\','/'),

)

【讨论】:

  • 以上是如何解决问题的?如果模板目录错误,那么 404 和 500 都不起作用,是吗?
【解决方案2】:

拼写正确,试试模板而不是模板?

【讨论】:

  • 什么意思?我使用的是templates 而不是模板。
  • 在您写的问题中:模板和它们位于template 目录下
  • @tutuDajuju,哦,是的,对不起,这是一个错字
  • @doniyor:请查看您问题中的最新评论以了解更多试验和错误
  • @tutuDajuju,是的,我的 500.html 只包含一些文本,没有任何需要 db 或任何外部连接的内容
【解决方案3】:

使用 Google 应用引擎时可能会发现类似的错误。 没错,模板应该是复数形式的“模板” 一个常见的错误是在 yaml 文件中包含模板目录

- url: /templates
  static_dir: templates

如果您删除这两行代码,假设您的路径如下:

path = os.path.join(os.path.dirname(__file__), 'templates/home.html')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-25
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 2015-03-05
    • 2015-02-12
    相关资源
    最近更新 更多