当我打电话
app.get('/', function(req, res)
{
res.render('index', {locals: {title: 'Hello, Node!' }});
});
它输出
TypeError: Object "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" +
"<html>" +
"</html>" +
"<title>" +
title +
"</title>" +
"<body>" +
"</body>" +
"<s>" +
"Hello, World" +
"</s>" has no method 'call'
at ServerResponse._render (/usr/local/lib/node/.npm/express/2.2.2/package/lib/view.js:377:21)
at ServerResponse.render (/usr/local/lib/node/.npm/express/2.2.2/package/lib/view.js:242:17)
at Object.<anonymous> (/home/william/www/html_public/app.js:36:6)
at param (/usr/local/lib/node/.npm/connect/1.3.0/package/lib/middleware/router.js:148:21)
at pass (/usr/local/lib/node/.npm/connect/1.3.0/package/lib/middleware/router.js:164:10)
at Object.router [as handle] (/usr/local/lib/node/.npm/connect/1.3.0/package/lib/middleware/router.js:170:6)
at next (/usr/local/lib/node/.npm/connect/1.3.0/package/lib/http.js:204:15)
at Object.bodyParser [as handle] (/usr/local/lib/node/.npm/connect/1.3.0/package/lib/middleware/bodyParser.js:76:7)
at next (/usr/local/lib/node/.npm/connect/1.3.0/package/lib/http.js:204:15)
at Object.methodOverride [as handle] (/usr/local/lib/node/.npm/connect/1.3.0/package/lib/middleware/methodOverride.js:35:5)
这是我的快速配置
app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(app.router);
app.use(express.cookieParser());
app.set('view engine', 'haml');
app.set("view options", { layout: false });
// Set directorys
app.use(express.static(public_dir));
app.set('views', __dirname + '/views');
});
我该如何解决这个问题。它似乎正在调用一个不存在的函数??
这是haml代码
!!!
%html
%title= title
%body
%s Hello, World
固定的!! 此配置修复了与 haml 库的兼容性
var haml = require('haml');
app.register('.haml', {
compile: function(str, options) {
return function(locals) {
return haml.render(str, {locals: locals});
}
}
});