我正在运行一个简单的服务器
var express = require('express')
var app = express()
app.set('view engine', 'ejs');
app.use(express.static('public'))
// home page request handler
app.get('/', function (req, res) {
res.render('home')
})
// initializes request listener
app.listen(process.env.PORT, process.env.IP, function(){
console.log("Server is listening");
})
当我对主页发出GET请求时,运行时会抛出以下错误
Error: Could not find include include file.
at getIncludePath (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:152:13)
at includeSource (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:276:17)
at /home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:629:26
at Array.forEach (native)
at Object.generateSource (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:605:15)
at Object.compile (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:509:12)
at Object.compile (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:358:16)
at handleCache (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:201:18)
at tryHandleCache (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:223:14)
at View.exports.renderFile [as engine] (/home/ubuntu/workspace/node_modules/ejs/lib/ejs.js:437:10)
我不明白这个错误。有任何想法吗?我在Cloud9工作。
我的目录结构是
v1.1
+---views
| +---- home.ejs
| +---- partials
| +------ header.ejs
| +------ footer.ejs
|
+----app.js
home.ejs
<% include header %>
<h1>welcome</h1>
<% include footer %>
header.ejs
<DOCTYPE! html>
<html>
<head>
<title>
<link rel="stylesheet" hreff="app.css">
</title>
</head>
<body>
footer.ejs
</body
</html>
答案 0 :(得分:9)
包含路径是相对路径,您需要更新路径以包含“partials”子文件夹,例如
<% include partials/header %>
<h1>welcome</h1>
<% include partials/footer %>
请参阅docs
答案 1 :(得分:0)
尝试一下:
<% include header %>
<h1>welcome</h1>
<% include footer%>
答案 2 :(得分:0)
尝试以下任何一种方法
program main
implicit none
integer i
real, allocatable, target :: a(:), b(:)
type ArrayVal
real, allocatable :: dat(:)
endtype
type(ArrayVal), allocatable :: arrays(:)
a = [1, 2]
b = [3, 4, 5]
arrays = [ArrayVal(a), ArrayVal(b)]
b(:) = b(:) + 100
do i = 1, size(arrays)
print *, i, " : ", arrays(i) % dat
enddo
end
!! gfortran-10 test.f90 && ./a.out
1 : 1.00000000 2.00000000
2 : 3.00000000 4.00000000 5.00000000
答案 3 :(得分:0)
<%- include('YOUR_PATH/GOES_HERE') %>
就我而言, OS Ubuntu,路径是这样的
<%- include('/media/username/diskname/foldername/nodejsApp/views/body/header.ejs') %>
编辑
我在写答案时忘记了“%”。