使用MEAN环境(Express 4)和EJS作为模板引擎,我正在努力解决路径问题。
代码示例:
app.set('view engine', 'ejs'); //using ejs as template engine instead of jade
app.set('views', __dirname + '/views'); //defining absolute path of views folder
//sample route for calling index.ejs
app.route('/')
.get(function(req, res) {
res.render('/pages/index'); //index.ejs is located in the pages folder (full path see list above)
});
出于某种原因,我不断收到此错误:
Error: Failed to lookup view "/pages/index" in views directory "/Users/admin/projectX/views"
恕我直言道路径应该正确加起来/ Users / admin / projectX / views / pages / index,那为什么不能找到它?!