Django配置404页面

修改环境

  1. DEBUG = False
  2. ALLOWED_OSTS = ["*"]

url配置

from blog.views import page_not_found
urlpatterns = [..]
handler404 = page_not_found

views配置

from django.shortcuts import render
def page_not_found(request, exception, template_name='404.html'):
	return render(request, template_name)

404页面

<meta name="description" content="404,网页不存在,网页丢失,请求失败">
<meta name="keywords" content="404页面">
<title>404 Not Found</title>
<style type="text/css">
    html, body {
        margin: 0;
        padding: 0;
    }
    body {
        font-family: PingFang SC, Helvetica Neue, Hiragino Sans GB, Segoe UI, Microsoft YaHei, sans-serif;
        font-size: 14px;
        line-height: 1.5;
        background: #f2f4f6;
        color: #323a45;
        -webkit-font-smoothing: antialiased;
    }
    .page {
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        line-height: 1.4;
    }
    .wrapper {
        padding-right: 378px;
        background-size: 278px;
        background-position: right;
        background-repeat: no-repeat;
    }
    .page-404 .wrapper {
        background-image: url(https://dn-coding-net-production-static.qbox.me/static/47b05c7cffd4d5e77ef99275abaf9017.png);
    }

    .page-500 .wrapper {
        background-image: url(https://dn-coding-net-production-static.qbox.me/static/528d7710668c5fd6e6dfb4f61c2f9b65.png);
    }
    h1 {
        margin: 0;
        color: #4f565f;
        font-size: 120px;
        font-weight: bold;
    }
    a {
        text-decoration: none;
    }
    .summary {
        margin-top: 0;
        margin-bottom: 40px;
        color: #76808e;
        font-size: 24px;
    }
    .button {
        display: inline-block;
        border-radius: 4px;
        box-sizing: border-box;
        cursor: pointer;
        outline: none;
        -webkit-transition: all .1s ease;
        transition: all .1s ease;
        border: 1px solid #323a45;
        background-color: #323a45;
        color: #fff;
        font-size: 18px;
        padding: 0 30px;
        height: 48px;
        line-height: 46px;
    }
    .button:hover {
        background-color: #425063;
        border: 1px solid #425063;
    }
</style>
<body>
    <div class="page page-404">
        <div class="wrapper">
            <h1>404!</h1>
            <p class="summary">页面,我找不到你,我找不到你啊~</p>
        </div>
    </div>
</body>

其他配置

  • 404

handler404:
page_not_found

  • 500

handler500:
server_error

  • 400

handler400:
bad_request

  • 403

handler403:
permission_denied

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值