跟路由设置
# 全局403
handler403 = 'logs.views.page_forbidden'
# 全局404
handler404 = 'logs.views.page_not_found'
# 全局500
handler500 = 'logs.views.page_error'
logs.views中的代码:
from django.shortcuts import render_to_response, render
def page_forbidden(request, exception):
response = render_to_response("403.html", {})
response.status_code = 403
return response
def page_not_found(request, exception):
response = render_to_response("404.html", {})
response.status_code = 404
return response
def page_error(exception):
response = render_to_response("500.html", {})
response.status_code = 500
return response
需要注意的,400和403页面需要传递request参数和exception参数,而500页面是不需要reqeust参数的!
网友评论