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页面的模板。

  1. 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>

  1. 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%;
}
  1. pic404.png
    在这里插入图片描述
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值