1

I am trying to learn django, and I have a small test server (not devel) to this effect where I am trying to host a small blog site (similar to the official tutorial).

I'd like to have custom 404 and 500 views, so, I have the following in urls.py:

from mystuff.views import Template404View, Template500View
handler404 = Template404View.as_view()
handler500 = Template500View.as_view()

and in my views.py, I have the following:

class Template404View(TemplateView):
    template_name = "404.html"

class Template500View(TemplateView):
    template_name = "500.html"

where, the 404.html and 500.html are present in my site_templates directory.

However, when I host this on my test server, instead of seeing 400 or 500 custom pages, all I see is Internal Server Error.

I have tried to look up similar questions on SO, and I see the following, but this does not seem to help...

Any advice would be appreciated...Thanks.

4

2 回答 2

1

我今天遇到了类似的问题:问题是我的 500 页中有德语元音变音符号,并且在渲染 500 页时,我的 apache 出现了内部服务器错误,因此引发了 apache 200 错误。所以检查你的500页,单独测试一下,看看调用的时候是否正确显示。

但是既然您正在学习本教程:为什么不采用第 3 章中描述的方法呢?只需编写您的 500.html 文件并将其放入 my_app/templates 中。这很好用,不需要额外的视图或 URL。

于 2013-10-03T18:22:50.937 回答
0

您正在从 mystuff 导入自定义视图,而它们是在 views.py 中定义的。尝试从我的 stuff.views 导入它们。

还设置 DEBUG=True 可以给你一些线索

于 2013-10-02T18:20:36.867 回答