这是我运行'Node server.js'并获得“监听”作为响应时获得的,然后打开浏览器找到它:
Error: Failed to lookup view "./login/login" in views directory "C:\Users\Ghanem\cloud1\views"
at EventEmitter.app.render (C:\Users\Ghanem\cloud1\node_modules\express\lib\application.js:555:17)
at ServerResponse.res.render (C:\Users\Ghanem\cloud1\node_modules\express\lib\response.js:938:7)
at C:\Users\Ghanem\cloud1\server.js:226:7
at Layer.handle [as handle_request] (C:\Users\Ghanem\cloud1\node_modules\express\lib\router\layer.js:82:5)
at next (C:\Users\Ghanem\cloud1\node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (C:\Users\Ghanem\cloud1\node_modules\express\lib\router\route.js:91:3)
at Layer.handle [as handle_request] (C:\Users\Ghanem\cloud1\node_modules\express\lib\router\layer.js:82:5)
at C:\Users\Ghanem\cloud1\node_modules\express\lib\router\index.js:267:22
at Function.proto.process_params (C:\Users\Ghanem\cloud1\node_modules\express\lib\router\index.js:321:12)
at next (C:\Users\Ghanem\cloud1\node_modules\express\lib\router\index.js:261:10)
我将'views'文件夹从'C:\ Users \ Ghanem \ cloud1 \ app \ server \ views'移动到'C:\ Users \ Ghanem \ cloud1 \ views'但仍然出现同样的错误(我移动它现在回来)。
以下是 server.js 中“./login/login”的代码行:
app.get("/login", function (req, res) {
// Show form, default value = current username
res.render("./login/login", { "username": req.session.username, "error": null });
});
这是结构:
./
app/
public/
css/
style.css
style.styl
img/
glyph.png
glyph1.png
js/
controllers/
homeController.js
loginController.js
signupController.js
form-validators/
accountValidator.js
emailValidator.js
loginValidator.js
resetValidator.js
views/
home.js
login.js
reset.js
signup.js
vendor/
bootstrap.min.css
bootstrap-modal.js
bootstrap-transition.js
jquery.form.js
jquery.min.js
server/
modules/
account-manager.js
country-list.js
email-dispatcher.js
email-settings.js
views/
el/
Models/
alert.jade
confirm.jade
form-errors.jade
lost-password.jade
reset-password.jade
404.jade
account.jade
home.jade
layout.jade
login.jade
print.jade
reset.jade
signup.jade
router.js
router.js.b
router.js
router.js.b
如何解决此问题?请记住,我已将views文件夹移动到根文件夹,但不知何故未将其检测到。
答案 0 :(得分:0)
根据您的评论:
app.set('views', path.join(__dirname, 'views'));
所以如果你写:
app.get("/login", function (req, res) {
// Show form, default value = current username
res.render("login/login", { "username": req.session.username, "error": null });
});
如果您的app/server/views/login/login.ejs
位于app / server文件夹中,则模板必须位于index.js
。