Express-手柄未填写{body}

在windows上使用express-handlebar@5.2.0和express@4.17.1使用node,但仍然无法在正文中呈现它:

File Setup:

testapp.js
[views]
main.handlebars
[views][layouts]
test.handlebars
//testapp.js

    const express = require('express');
    const exhbr = require('express-handlebars');
    const app = express();
    const port = 3031;

    app.engine('handlebars', exhbr({}));
    app.use(express.static('public'));
    app.set('view engine', 'handlebars');
    app.get('/', (req, res) => {
        res.render('main', { layout: 'test' });
    });
    app.listen(port, () => console.log(`App listening to port ${port}`));
<!--test.handlebars-->

<h1>Test</h1>
<!-- main.handlebars -->

<!DOCTYPE html>
<html lang="en">
<body>
    {{{body}}}
</body>
</html>

只返回<h1>Test</h1>,并且还没有插入到正文中。

我也尝试了以下,只是为了确保它看起来在正确的地方。

res.render('doesnt_exist');
Error: Failed to lookup view "doesnt_exist" in views directory "c:\wamp\www\rethinkdb_rest\views\"

res.render('main', { layout: "doesnt_exist" });
Error: ENOENT: no such file or directory, open 'c:\wamp\www\rethinkdb_rest\views\layouts\doesnt_exist.handlebars'

转载请注明出处:http://www.resmedchina.com/article/20230526/1211196.html