错误:无法查找视图"布局"在views目录中

时间:2016-11-10 14:11:34

标签: node.js express routes

我收到的错误如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文件夹结构:

This is the formHandling folder structure

1 个答案:

答案 0 :(得分:0)

我删除了 app.use(expresslayouts)。为我工作