当前位置:  开发笔记 > 编程语言 > 正文

如何改变快递的车把延伸?

如何解决《如何改变快递的车把延伸?》经验,为你挑选了1个好方法。

我是node.js的新手,我想使用把手模板引擎,但缩短了扩展名hbs.

这是原始代码(来源):

var handlebars = require('express3-handlebars')
.create({ defaultLayout: 'main' });
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');

它适用于带handlebars扩展名的模板,但我将其更改为:

var handlebars = require('express3-handlebars')
.create({ defaultLayout: 'main' });
app.engine('hbs', handlebars.engine);
app.set('view engine', 'hbs');

并将所有模板扩展名更改为hbs.但是,现在我收到此错误:

Error: ENOENT: no such file or directory, open '/path/to/node/myproject/views/layouts/main.handlebars'
   at Error (native)

我也试过了

var handlebars = require('express3-handlebars')
.create({ defaultLayout: 'main' , extname : '.hbs'});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');

按照这里的答案,

但我的结果是:

Error: Failed to lookup view "500" in views directory "/path/to/myproject/views"
   at EventEmitter.render (/path/to/myproject/node_modules/express/lib/application.js:579:17)
   at ServerResponse.render (/path/to/myproject/node_modules/express/lib/response.js:961:7)
   at /path/to/myproject/app.js:96:6
   at Layer.handle_error (/path/to/myproject/node_modules/express/lib/router/layer.js:71:5)
   at trim_prefix (/path/to/myproject/node_modules/express/lib/router/index.js:310:13)
   at /path/to/myproject/node_modules/express/lib/router/index.js:280:7
   at Function.process_params (/path/to/myproject/node_modules/express/lib/router/index.js:330:12)
   at next (/path/to/myproject/node_modules/express/lib/router/index.js:271:10)
   at Layer.handle_error (/path/to/myproject/node_modules/express/lib/router/layer.js:67:12)
   at trim_prefix (/path/to/myproject/node_modules/express/lib/router/index.js:310:13)

我也尝试了其他的东西,但没有一个工作,所以想知道如何解决这个问题?



1> supermario..:

这样就可以了:

exphbs = require('express3-handlebars'),
app.engine('hbs', exphbs({defaultLayout: 'main', extname: '.hbs'}));
app.set('view engine', 'hbs');


该软件包已被弃用,请使用`express-handlebars`。https://www.npmjs.com/package/express3-handlebars
推荐阅读
mobiledu2402852357
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有