1

我很喜欢编写 node.js 程序。

这是我的 app.js 文件:

var express = require('express');
var app = express();

app.configure(function(){
    app.set('view engine', 'jade');
});

app.get('/index/:name',function(req, res){
    res.render('index', {
        title: req.params.name
    });
});

app.listen(8080);

这是我的 index.jade

!!! 5
html
  head
    title= title

当我从网络浏览器运行 call localhost:8080/index/example 时,我收到以下错误:

Error: Failed to lookup view "index.jade"
    at Function.render (/home/yusuf/Masaüstü/node/node_modules/express/lib/application.js:489:17)
    at ServerResponse.render (/home/yusuf/Masaüstü/node/node_modules/express/lib/response.js:716:7)
    at /home/yusuf/Masaüstü/node/app.js:9:6
    at callbacks (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:160:37)
    at param (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:134:11)
    at param (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:131:11)
    at pass (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:141:5)
    at Router._dispatch (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:169:4)
    at Object.router [as handle] (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:32:10)
    at next (/home/yusuf/Masaüstü/node/node_modules/express/node_modules/connect/lib/proto.js:190:15)

问题是什么?我该如何解决?

4

1 回答 1

0

您需要设置您的意见文件夹

app.configure(function(){
    app.set("view engine", "jade");
    app.set("views", __dirname + "/public");
});

如果这不起作用,请尝试

app.set('view engine', 'jade');
于 2015-01-02T19:46:02.013 回答