我自己编写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
当我从网络浏览器调用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)
有什么问题?我怎么解决?
答案 0 :(得分:0)
您需要设置视图文件夹
app.configure(function(){
app.set("view engine", "jade");
app.set("views", __dirname + "/public");
});
如果这不起作用,请尝试
app.set('view engine', 'jade');