错误:无法在视图目录中查找视图“布局”
Posted
技术标签:
【中文标题】错误:无法在视图目录中查找视图“布局”【英文标题】:Error: Failed to lookup view "layout" in views directory 【发布时间】:2017-03-24 14:28:30 【问题描述】:我收到类似Error: Failed to lookup view "layout" in views directory
的错误。下面是文件的源代码以及文件夹结构。
index.ejs
<!DOCTYPE html>
<html>
<head>
<title>Form Handling</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
server.js
//require express
var express = require('express')
var app = express()
var expressLayouts = require('express-ejs-layouts')
//Setting the View Engine as EJS
app.set('view engine', 'ejs')
app.use(expressLayouts)
//Specifying the router file
var router = require('./routes')
app.use('/', router)
//Starting a server on port 8004
app.listen(8004, function ()
console.log('Server is running at port 8004...!');
)
routes.js
//require express
var express = require('express')
var app = express()
//creating a router object
var router = express.Router()
//export these routes to other files
module.exports = router
//Routes
router.get('/', function (req, res)
res.render('index');
)
这是formHandling文件夹结构:
【问题讨论】:
【参考方案1】:我删除了 app.use(expresslayouts)。为我工作
【讨论】:
以上是关于错误:无法在视图目录中查找视图“布局”的主要内容,如果未能解决你的问题,请参考以下文章
Nodejs / Express:错误:无法在视图目录中查找视图“错误”
Express 错误 500:无法在视图目录“/app/views”中查找视图“index.html”
Angular Universal (s-s-r) 错误:无法在视图目录中查找视图“索引”
节点无法在 Express/react 应用程序中查找视图“错误”