django中自定义404错误页面

自定义404页面,如下5个步骤:
1)使用自定义的404页面,必须在setting文件修改DEBUG = False(即关闭debug调试模式)
2)必须在setting文件修改ALLOWED_HOSTS = ['*']或者ALLOWED_HOSTS = ['127.0.0.1', 'localhost''],否则启动项目会提示:
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
3)在urls文件中,添加如下代码:
from django.conf.urls import handler404, handler500
handler404 = sign_views.page_not_found #handler404 = "你的app.views.函数名"
4)在views文件中添加page_not_found函数
def page_not_found(request):
return render_to_response("404.html")
5)在app的templates下建立404.html
原文地址:https://www.cnblogs.com/xtt-w/p/6240172.html