Nodejs 哈巴狗扩展
Nodejs pug extend
这里绝对是新手。我刚刚使用 node.js 设置了新服务器,但停留在哈巴狗视图上。试图将 login.pug 扩展到 index.pug 但我得到的只是页脚和页眉之外的空白内容。我哪里做错了?请帮助...
p/s: 哈巴狗已经安装
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") 👱
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") 💌
input( class="default-input" id="user-email" type="email" placeholder="user email" value="" spellcheck="false" required)
app.get('/', function (req, res) {
res.render('index');
});
您正在渲染 index.pub。但是,您还没有将 login.pub 扩展到您的索引中。您而是将索引扩展到 login.pub
如果只是将渲染改成登录,应该可以看到新的内容。
app.get('/', function (req, res) {
res.render('login');
});
这里绝对是新手。我刚刚使用 node.js 设置了新服务器,但停留在哈巴狗视图上。试图将 login.pug 扩展到 index.pug 但我得到的只是页脚和页眉之外的空白内容。我哪里做错了?请帮助... p/s: 哈巴狗已经安装
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") 👱
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") 💌
input( class="default-input" id="user-email" type="email" placeholder="user email" value="" spellcheck="false" required)
app.get('/', function (req, res) {
res.render('index');
});
您正在渲染 index.pub。但是,您还没有将 login.pub 扩展到您的索引中。您而是将索引扩展到 login.pub
如果只是将渲染改成登录,应该可以看到新的内容。
app.get('/', function (req, res) {
res.render('login');
});