当前位置:   article > 正文

django 处理和自定义异常_django自定义异常

django自定义异常

#首先在项目的urls.py,设置404和500

  1. from  index import views
  2. handler404=views.page_not_found
  3. handler500 = views.page_error

然后定义index模块的views.py

  1. def page_not_found(request,exception):
  2.     return render(request,"404.html",status=404)
  3. def page_error(request,exception):
  4.     return render(request,"500.html",status=500)

settings.py 

DEBUG = Fasle 

以上自定义异常页面才生效

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/979474
推荐阅读
相关标签
  

闽ICP备14008679号