基于Django 2.2版本实现
Django下的错误类型主要有四种: - 400:客户端错误 - 403:没有权限 - 404:页面未找到 - 500:服务器错误
DEBUG = False
自定义错误页面在Debug = True
时不生效
You Don't have permission !
Please contact ops-coffee.cn
from django.shortcuts import render
def bad_request_view(request, exception, template_name='errors/400.html'):
return render(request, template_name)
def permission_denied_view(request, exception, template_name='errors/403.html'):
return render(request, template_name)
def page_not_found_view(request, exception, template_name='errors/404.html'):
return render(request, template_name)
def error_view(request, exception, template_name='errors/500.html'):
return render(request, template_name)
handler400 = 'webapp.views.bad_request_view'
handler403 = 'webapp.views.permission_denied_view'
handler404 = 'webapp.views.page_not_found_view'
handler500 = 'webapp.views.error_view'