【问题标题】:ExpressJs: Failed to lookup view "index" in views directoryExpressJs:无法在视图目录中查找视图“索引”
【发布时间】:2022-11-30 02:41:51
【问题描述】:

我正在尝试在我的代码中添加 hbs 模板,但出现无法在视图目录中查找视图“索引”的错误

const express = require("express")
const path = require("path")
require("../src/db/conn")

const app = express();
const port = process.env.PORT || 3000;
const static_path = path.join(__dirname, "../public")

app.use(express.static(static_path))
app.set("view engine" , "hbs");


app.get("/" , (req,res)=>{
    res.render("index")
})

app.listen(port , ()=>{
    console.log("server is listening on port no 3000" )
})

这是我的代码,我还创建了一个观点文件夹和一个索引.hbs该文件夹内的文件

【问题讨论】:

    标签: javascript express


    【解决方案1】:

    app.set("视图引擎", "hbs"); 在这一行之后添加

    app.set("视图", "视图");

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 2021-06-26
      • 2021-07-23
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 1970-01-01
      • 2016-08-05
      • 1970-01-01
      相关资源
      最近更新 更多