示例:假如我的項(xiàng)目名稱為nocmt app名稱為blog
首先你要在templates內(nèi)有自己的404.html和500.html文件(即和你的其他html文件在同級(jí)目錄下)
然后在/nocmt/nocmt/urls.py 中加入:
from blog import views
handler404 = views.page_not_found
handler500 = views.page_error
然后在 /nocmt/blog/views.py 中加入:
def page_not_found(request):
return render_to_response('blog/404.html')
def page_error(request):
return render_to_response('blog/500.html')
輸入一個(gè)不存在的頁(yè)面 出現(xiàn)自定義的404頁(yè)面的時(shí)候 就代表你設(shè)置成功了庞溜!
Paste_Image.png
Paste_Image.png
這是我做的404和500頁(yè)面,如果你想下載:SimpleBugHtmlFile