【发布时间】:2023-03-19 23:59:01
【问题描述】:
您好,我需要帮助车把不渲染我的部分,而是给我下面的错误。
错误:找不到部分默认值/头 在 Object.invokePartial (C:\node-projects\cms blog\node_modules\handlebars\dist\cjs\handlebars\runtime.js:332:11) 在 Object.invokePartialWrapper [as invokePartial] (C:\node-projects\cms blog\node_modules\handlebars\dist\cjs\handlebars\runtime.js:84:39) 在 Object.eval [as main] (在 createFunctionContext 进行评估(C:\node-projects\cms blog\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:262:23),:8:31 ) 在 main (C:\node-projects\cms blog\node_modules\handlebars\dist\cjs\handlebars\runtime.js:208:32) 在 ret (C:\node-projects\cms blog\node_modules\handlebars\dist\cjs\handlebars\runtime.js:212:12) 在 ret (C:\node-projects\cms blog\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:519:21) 在 ExpressHandlebars._renderTemplate (C:\node-projects\cms blog\node_modules\express-handlebars\lib\express-handlebars.js:265:9) 在 ExpressHandlebars。 (C:\node-projects\cms blog\node_modules\express-handlebars\lib\express-handlebars.js:182:15)
app.js 文件如下
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const hbs = require('express-handlebars');
/*Use express*/
const app = express();
/* configure mongoose to connect to mongo DB*/
const {mongoDbUrl, PORT} = require('./config/configuration');
//Remove mongoose warning
mongoose.Promise = global.Promise;
mongoose.connect(mongoDbUrl, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log('mongodb connected'))
.catch(err => console.log(err));
/* configure express app */
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname , "public")));
/* Set up view engine to use handlebars*/
app.engine(
"handlebars",
hbs({
extname: "hbs",
defaultLayout: false,
})
);
app.set('view engine', 'handlebars');
/* Routes */
app.use('/', (req, res) => {
res.render('layout/default');
})
app.listen(PORT, () => {
console.log(`server connected on ${PORT} `);
});
【问题讨论】:
标签: node.js handlebars.js