Django 错误跳转页面

Django 错误跳转页面

2018-04-10 17:21 by xx--, ... 阅读, ... 评论, 收藏, 编辑

原网站:https://blog.csdn.net/goupper1991/article/details/50736826

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页面


了)

<!DOCTYPE HTML>
<html>  
<head>  
<meta charset="UTF-8" />  
<meta name="viewport" content="width=device-width, initial-scale=1">  
<meta name="robots" content="none" />  
<title>404 Not Found</title>  
<style>  
*{font-family:"Microsoft Yahei";margin:0;font-weight:lighter;text-decoration:none;text-align:center;line-height:2.2em;}  
html,body{height:100%;}  
h1{font-size:100px;line-height:1em;}  
table{width:100%;height:100%;border:0;}  
</style>  
</head>  
<body>  
<table cellspacing="0" cellpadding="0">  
<tr>  
<td>  
<table cellspacing="0" cellpadding="0">  
<tr>  
<td>  
<h1>404</h1>  
<h3>大事不妙啦!</h3>  
<p>你访问的页面好像不小心被作者给弄丢了~<br/>
<a href="/">返回首页 ></a>
</p>  
</td>  
</tr>  
</table>  
</td>  
</tr>  
</table>  
</body>  
</html>  

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值