【发布时间】:2021-07-24 01:02:04
【问题描述】:
希望你们都做得很好,我是 Expressjs 的新手并在其中做一个项目。 实际上,我在渲染视图目录中名为 index.hbs 的文件夹中的文件时遇到问题, 当我尝试访问时发现此错误: 错误:无法在视图目录“C:\Users\HBK1007\Desktop\ExpressjsFyPEPakTourisum\template\views”中查找视图“/blogger_dasboard”
我还附上了文件夹结构图像和我的代码
这里是代码enter image description here `
const express = require("express")
const app = express()
const path = require('path')
const port = 8000;
const hbs =require('hbs')
const bcrypt =require("bcryptjs")
// establishing db connection
require('./db/db_connec');
// Getting the collection of DB
const Registration=require('./models/registrationdb')
const NewsletterSubsciber=require('./models/newsletter')
const ContactUs_Client =require("./models/contactus")
// this is for DB data conersions
app.use(express.json());
app.use(express.urlencoded({extended:false}))
//public static port
const static_path = path.join(__dirname, '../public')
const tempalte_path = path.join(__dirname, '../template/views')
const bloggerdashboard_path = path.join(__dirname, '../template/views/blogger_dashboard')
const partials_path =path.join(__dirname,'../template/particles')
app.set('view engine', 'hbs');
app.set('views', tempalte_path)
hbs.registerPartials(partials_path)
app.use(express.static(static_path))
// BloggerDashboard Routes
app.get('/blogger_dashboard', (req, res) => {
res.render('/blogger_dasboard')
})
app.listen(port, () => {
console.log("Listning to portss ")
})
【问题讨论】:
-
这些答案解决了你的问题吗?
标签: express handlebars.js render router