在Django中处理自定义错误页面(404,500)

时间:2019-09-24 13:12:17

标签: django

为什么当我单击页面不存在时,项目文件夹中会出现错误页面,但我看到页面django的出现以及所有代码都是正确的

from django.shortcuts import (
render_to_response
)
from django.template import RequestContext

def handler404(request, exception):
    context = RequestContext(request)
    err_code = 404
    response = render_to_response('404.html', {"code":err_code}, context)
    response.status_code = 404
    return response
def handler500(request, exception):
    context = RequestContext(request)
    err_code = 500
    response = render_to_response('500.html', {"code":err_code}, context)
    response.status_code = 500
    return response

0 个答案:

没有答案