提问者:小点点

错误:找不到包含文件“partials/head”


在这里输入图像描述我正在尝试运行一个ejs文件,并得到错误:无法找到包含文件“partials/head”。

我已经检查了stackoverflow和github的大部分文章,但是无法解决它...

错误:在getIncludePath(C:\users\Junia\Desktop\Node\Node_Desktop\EJS\lib\EJS.js:162:13)中找不到包含文件“partials/head”,请在includeSource(C:\users\Junia\Desktop\Node\Node_Module\EJS\lib\EJS.js:306:17)中C:\users\Junia\Desktop\Node\Node_Module\EJS\lib\EJS.js:672:26中Array.Foreach()中

var express=require('express');

var app=express();

var router=express.Router();

var mysql=require('mysql');

var cookieParser=require('cookie-parser');

var session=require('express-session');

app.use(session({
    secret: 'secret',
    resave: true,
    saveUninitialized: true
    //cookie : { maxAge : 60000 }
}));

var path=require('path');

var bodyParser=require('body-parser');

app.use(express.static('/'));

//Serves all the request which includes /images in the url from Images folder

app.use('/images', express.static(__dirname + '/images'));

app.use('/bs4', express.static(__dirname + '/bs4'));

app.use(cookieParser());

const ejsLint = require('ejs-lint');

var con=mysql.createConnection(

{

host:'localhost',

user:'root',

password:'',

database:'shintoj'

});

var path = require('path');

app.use('/',router);

app.use('/',express.static(__dirname + '/'));

app.set('views', path.join(__dirname, 'views/pages'));

app.set('view engine', 'ejs');// use res.render to load up an ejs view file

// index page 

router.get('/', function(req, res) {

    //res.send('Welcome');

    res.render('index');

});

app.listen(8080);

console.log('8080 is the magic port');

console.log(app.get('views'));

index.ejs文件

<head>

<%- include partials/head %>

</head>

<body class="container">

<header>

<% include partials/header.ejs %>

</header>

    <div class="jumbotron">

        <h2>Welcome to our services .</h2>

        <p>Hello</p>

    </div>

<footer>

<% include partials/footer.ejs %>

</footer>   

预期的实际结果是..当我运行节点server.js时,它应该显示index.ejs文件


共1个答案

匿名用户

从index.ejs文件中的ejs标记中删除include tag header和footer。或者jsut正确地包含页眉和页脚文件。像这样

<%- include views-directory/filename  %>