一、在URLconf下重新定义Django内置的handler函数:
mysite就是你的app
HttpResponseNotFound, HttpResponseServerError, HttpResponseForbidden, HttpResponseBadRequest |
views中编写
返回是 return HttpresponseNotFound()
from django.http import HttpResponse.HttpresponseNotFound
出错的函数打log就好了 不要做复杂操作
二、自己建立404.html,500.html等放到公共Templates目录下
这两种方式都只在DEBUG=False时起作用,最方便的方式是采用第二种方式,而如果有特殊的需求,例如当页面出错时想自己处理,那么也可以自己定义handler view来处理。