custom handler404 =>标准错误页面

时间:2015-03-22 18:11:48

标签: python django

当我尝试将自己的视图用于错误404时,我得到一个标准的错误页面。那么,我现在做了什么:

# root settings.py
DEBUG = False
ALLOWED_HOSTS = [
    '*'
]

# blog urls.py
handler404 = 'views.custom_404'

# blog views.py
def custom_404(request):
    return HttpResponse("Hello world, I'm a custom error 404") 

另外,要在Django测试服务器上本地试用,我会这样运行:

python manage.py runserver --insecure

但是当我去一些不存在的页面时,我得到的是:

Not Found
The requested url blablabla

因此,出于某种原因,我没有看到自己的消息Hello world, I'm a custom error 404

1 个答案:

答案 0 :(得分:2)

404处理程序不是每个应用程序,它们只能从主urls.py。

设置