首页 > 解决方案 > 无法在 express 的视图目录中查找视图“索引”

问题描述

同时学习快递我无法解决这个错误,它说在视图目录中查找视图“索引”失败,而我的文件夹结构看起来像这样

在此处输入图像描述

我尝试设置路径无效

const pathDirectory = path.join(__dirname, '../public')
const viewsPath = path.join(__dirname, '../templates/views')
const partialsPath = path.join(__dirname, '../templates/partials')

app.set('views', path.join(__dirname, viewsPath));
hbs.registerPartials(partialsPath)

app.use(express.static(pathDirectory))

应该显示 index.hbs 的页面

标签: express

解决方案


尝试包括

app.set('view engine', 'hbs')

express.static方法。

那会有所帮助。


推荐阅读