Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 定制手柄404=>;标准错误页_Python_Django - Fatal编程技术网

Python 定制手柄404=>;标准错误页

Python 定制手柄404=>;标准错误页,python,django,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 err

当我尝试使用自己的视图处理错误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

因此,由于某些原因,我没有看到我自己的消息
你好,我是一个自定义错误404

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

谢谢!我现在检查一下。我遇到了另一个问题。如果我只是显示一条消息,那就没关系了。但是,如果我尝试使用位于
博客/templates
中的e-template页面
404.html
,则会出现服务器错误500。你能告诉我如何解决这个问题吗?PS.settings.py知道
blog/templates
路径,并且该文件夹中有一个真正的
404.html
文件。我尝试如下方式渲染
404.html
return render\u to\u response('404.html',context\u实例=RequestContext(request))