zoukankan      html  css  js  c++  java
  • 一个简单的blog系统(十三) 增加404页面

    1. 假定,当所有的路径都没有匹配的时候,我们就给它返回一个404页面。

      首先,打开index.js,在function checkLogin(req, res, next){} 的前面添加如下所示代码:

    router.use(function(req, res) {
            res.render('404');
        })

      然后,我们在views文件下创建一个404.ejs的文件,用来保存404页面,在其中添加如下代码:

    <!DOCTYPE html>
    <html>
    <head>
          <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>MicroBlog</title>
    </head>
    <body>
        <div>
            <a href="http://imooc.com/">
                <img id="error404-image" alt="404 page not found" src="http://huwshimi.com/wp-content/themes/huwshimi/images/404.png" style="100% height:100%">
            </a>
        </div>
    </body>
    </html>

      至此,我们就给页面添加了一个美丽的404页面。

  • 相关阅读:
    哈夫曼树
    MongoDB
    Node.js 搭建Web
    Node.js
    HDFS编程
    scp
    MapRecude
    级数
    (转)MySQL百万级数据库优化
    ssh
  • 原文地址:https://www.cnblogs.com/yuity/p/5305195.html
Copyright © 2011-2022 走看看