#首先在项目的urls.py,设置404和500
from index import views
handler404=views.page_not_found
handler500 = views.page_error
然后定义index模块的views.py
def page_not_found(request,exception):
return render(request,"404.html",status=404)
def page_error(request,exception):
return render(request,"500.html",status=500)
settings.py
DEBUG = Fasle
以上自定义异常页面才生效