gpt4 book ai didi

javascript - 使用 jade 时出现错误 : "Failed to lookup view"

转载 作者:太空宇宙 更新时间:2023-11-04 02:42:09 25 4
gpt4 key购买 nike

我很喜欢编写 Node.js 程序。

这是我的 app.js 文件:

var express = require('express');
var app = express();

app.configure(function(){
app.set('view engine', 'jade');
});

app.get('/index/:name',function(req, res){
res.render('index', {
title: req.params.name
});
});

app.listen(8080);

这是我的index.jade

!!! 5
html
head
title= title

当我从网络浏览器运行 call localhost:8080/index/example 时,出现以下错误:

Error: Failed to lookup view "index.jade"
at Function.render (/home/yusuf/Masaüstü/node/node_modules/express/lib/application.js:489:17)
at ServerResponse.render (/home/yusuf/Masaüstü/node/node_modules/express/lib/response.js:716:7)
at /home/yusuf/Masaüstü/node/app.js:9:6
at callbacks (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:160:37)
at param (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:134:11)
at param (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:131:11)
at pass (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:141:5)
at Router._dispatch (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:169:4)
at Object.router [as handle] (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:32:10)
at next (/home/yusuf/Masaüstü/node/node_modules/express/node_modules/connect/lib/proto.js:190:15)

有什么问题吗?我该如何解决?

最佳答案

您需要设置 View 文件夹

app.configure(function(){
app.set("view engine", "jade");
app.set("views", __dirname + "/public");
});

如果这不起作用,请尝试

app.set('view engine', 'jade');

关于javascript - 使用 jade 时出现错误 : "Failed to lookup view",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13667684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com