Django配置404页面
作者:互联网
目录
一.settings配置
1.首先需要在settings中将DEBUG由原来的True改为False
DEBUG = False
2.需要设置
ALLOWED_OSTS = ["*"]
二.url设置
三.views中设置
def page_not_found(request,**kwargs):
# 全局404处理函数
response = render_to_response('404.html', {})
response.status_code = 404
return response
上面就是配置404的全部过程
四.最后附一个404页面的模板。
404html
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>404</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/reset.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/animate.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}">
<script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script>
</head>
<body class="bg404 errorpage">
<section>
<div class="wp">
<div class="cont">
<img src="{% static 'images/pic404.png' %}"/>
<br/><br/><br/><br/>
<p>wow~这个页面被外星人抢走了~</p>
<br/>
<span>Wow~ this page was the alien took ~</span>
</div>
</div>
</section>
</body>
</html>
404.css
.bg404 {
text-align: center;
}
.errorpage {
width: 100%;
height: 100%;
color: #23353c;
}
.errorpage .wp {
width: 1000px;
}
.errorpage .cont {
width: 100%;
height: 50%;
position: relative;
margin-top: 25%;
}
pic404.png
标签:100%,Django,width,404,errorpage,response,页面 来源: https://blog.csdn.net/qq_38418803/article/details/110006609