from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
from django.shortcuts import render, HttpResponse
def handler404_page(request, exception):
return HttpResponse('404页面')
handler404 = handler404_page
在项目的ROOT_URLCONF
里面定义handler404,如上所示,当页面发生404 not found 时会返回HttpResponse(‘404页面‘)
,同样也可以使用模板返回, 500的页面和404相同的设置
原文:https://www.cnblogs.com/ivy-blogs/p/12245708.html