express - 无法在 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 的页面
解决方案
尝试包括
app.set('view engine', 'hbs')
后express.static
方法。
那会有所帮助。
推荐阅读
- javascript - 在 nodejs 中的 Square API 中格式化来自 webhook 的响应
- docker - 如何让管理员使用 Docker 在本地运行
- android - 如何获取 AdView 横幅高度
- javascript - 正确位于 Json 中的 Filterring 数组
- c++ - 如何知道函数C++中参数的格式
- maven - 如何使用系统属性将参数传递给 runner/maven 构建
- spring-boot - Spring Cloud Vault:令牌(spring.cloud.vault.token)不能为空
- reactjs - prismic sm --setup:运行时没有这样的文件或目录
- python - 根据提到的逻辑将 Dataframe 从宽减少到长的有效方法
- python-3.x - 如何强制 Discord 在没有嵌入的情况下发送链接?