【问题标题】:Nodejs pug extendNodejs哈巴狗扩展
【发布时间】:2019-03-31 12:37:46
【问题描述】:

这里绝对是初学者。我刚刚使用 node.js 设置了新服务器,但停留在 pug 视图上。试图将 login.pug 扩展到 index.pug 但我得到的只是除了页脚和头部之外的空白内容。我哪里做错了?请帮忙... p/s: pug 已经安装了

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

// for parsing application/json
app.use(bodyParser.json());

// for parsing application/xwww-
app.use(bodyParser.urlencoded({
    extended: true
}));
//form-urlencoded

app.get('/', function (req, res) {
    res.render('index');
});

// for parsing multipart/form-data
app.use(upload.array());
app.use(express.static('public'));
//index.pug

doctype html
html(lang="en")
head
    meta( charset="utf-8")
    meta( name="viewport" content="width=device-width, initial-scale=1")
    title COMPANY WEBAPP
    meta( name="description" content="MKE Web App.")
    meta( name="keywords" content="MKE Web App.")
    link( rel="shortcut icon" type="image/png" href="img/icon/favicon.png")
    link( rel="stylesheet" type="text/css" href="css/index.css")
    link( rel="stylesheet" type="text/css" href="css/default.css")

    body
        block content

        footer
            p( id="copyright") Copyright © 2019
            p( id="visitcount") Loading...

        script( type="text/javascript" src="/socket.io/socket.io.js")
        script( type="text/javascript" src="js/hmac-sha3.js")
        script( type="text/javascript" src="js/index.js")


//login.pug
extends index

block content
    div(class="login-continer")
        form( class="form-login default-box" method="POST" action="/login")
            div
                label( for="user-id") <strong>User ID :</strong>
                span( class="span-login-symbol")  &#128113;
                input( class="default-input" id="user-id" type="test" placeholder="user id" value="" spellcheck="false" required)
            div
                label( for="user-email") <strong>Email :</strong>
                span( class="span-login-symbol") &#128140;
                input( class="default-input" id="user-email" type="email" placeholder="user email" value="" spellcheck="false" required)

【问题讨论】:

    标签: javascript node.js pug


    【解决方案1】:
    app.get('/', function (req, res) {
        res.render('index');
    });
    

    您在获取时呈现 index.pub。但是,您还没有将 login.pub 扩展到您的索引中。相反,您将索引扩展到您的 login.pub

    如果你只是将渲染更改为登录,你应该可以看到新的内容。

    app.get('/', function (req, res) {
        res.render('login');
    });
    

    【讨论】:

      猜你喜欢
      • 2022-08-14
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多