setting.py文件配置
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['*']
主程序目录建立view.py文件
from django.shortcuts import render
def page_not_found(request):
return render(request, '404.html')
def page_permission_denied(request):
return render(request, '404.html')
def page_inter_error(request):
return render(request, '404.html')
主url.py配置handler
from django.conf.urls import url, include, handler403, handler404, handler500
from . import view
urlpatterns = [
···
]
# 配置异常页面
handler403 = view.page_permission_denied
handler404 = view.page_not_found
handler500 = view.page_inter_error
Enjoy Your 404 Error.