django设置404

By 肖奈
2017-09-12
4627 read


django404,500错误自定义页面:


1.设置settings文件


DEBUG = False


ALLOWED_HOSTS = ['127.0.0.1', 'localhost']或者
ALLOWED_HOSTS = ['*']


2.配置urls文件


from django.conf.urls import handler404, handler500


handler404 = "login.views.page_not_found"
(handler404 = "你的app.views.函数名")
handler500 = "login.views.page_error"


3.在views文件中定义函数page_not_found和page_error 


from django.shortcuts import render_to_response

def page_not_found(request):
    return render_to_response('404.html')


def page_error(request):
    return render_to_response('500.html')


4.在app的templates下建立404.html和500.html文件(文件内就是你自定义的404或者500页面


CentOS下Python2.6升级到Python3
django 正则

Comments

暂无评论,还不快来坐沙发...

Leave a Reply