我收到的错误如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文件夹结构:
答案 0 :(得分:0)
我删除了 app.use(expresslayouts)。为我工作