一.settings配置

1.首先需要在settings中将DEBUG由原来的True改为False

DEBUG = False

2.需要设置

ALLOWED_OSTS = ["*"]

二.url设置

 Django配置404页面

三.views中设置

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

上面就是配置404的全部过程

四.最后附一个404页面的模板。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>错误页面</title>
    <link rel="stylesheet" type="text/css" href="/static/css/404.css"/>
</head>

<body style="background:#0186a7;">

<!---404--->
<div class="error_new_bg pr">
    <div class="error_new_content">
        <div class="error_new pa">
            <div class="fl error_new_left"><img src="/static/img/404.png"></div>
            <div class="fl error_new_right">
                <div class="error_detail">
                    <p class="error_p_title">哎呦~ 页面没有找到!</p>
                    <p class="error_p_con">※ 别急,工程师正在紧急处理,马上就好。</p>
                    <p class="error_p_con">※ 您可联系QQ:1119564976,通知二当家的开发人员!</p>
                    <p class="error_p_con">※ 感谢您对博客小屋的支持,请您耐心等待!</p>
                </div>

                <p class="error_new_right_btn pr">
                    <a href="/index" class="type-2 type-3">
                        <i> 返回首页</i>
                        <i> 返回首页 </i>
                        <i> 返回首页 </i>
                        <i> 返回首页 </i>
                    </a>
                </p>
            </div>
        </div>
    </div>
</div>
</body>
</html>
404.html

相关文章:

  • 2022-12-23
  • 2021-07-05
  • 2021-12-10
  • 2021-09-22
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-11
  • 2021-06-23
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案