注意:django要实现全局的404,500等统一配置,需要提前把debug设置为false
1、项目的 urls.py里面写入:
# 全局 404 配置
handler404 = 'test.views.page_not_found'
2、项目的views.py里面写入如下:
# 全局配置 # 全局404
def page_not_found(request, exception):
return render(request, 'test/page/404.html', {}, status=404) # 404.html页面
3、上面路径下要有一个404.html
4、效果图如下
原创文章,转载请注明出处:http://124.221.219.47/article/django_404/