错误:无法在视图目录中查找视图“ / packages”

时间:2018-07-09 18:43:00

标签: node.js express express-handlebars

我的views文件夹中已经设置了handelbars视图“ packages”。 我在“ routes”文件夹中设置了一个users.js文件,如下所示:

var express = require('express');
var router = express.Router();

//Get Homepage
router.get('/', function(req,res){
    res.render('index');
});

module.exports = router;

“ routes”文件夹中的index.js文件也是:

var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var exphbs = require('express-handlebars');

var routes = require('./routes/index');
var users = require('./routes/users');

//Init App
var app = express();

//View Engine
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', exphbs({defaultLayout: 'layout'}));
app.set('view engine', 'handlebars');

//Set Static Folder
app.use(express.static(path.join(__dirname, 'public')));

//BodyParser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));

app.use('/', routes);
app.use('/users', users);

//Set Port
app.set('port', (process.env.PORT || 3000));

app.listen(app.get('port'), function(){
    console.log('Server started on port '+ app.get('port'))
}); 

我的app.js文件如下:

node {
    stage ("Checkout") {
        checkout([$class: 'AccurevSCM', depot: 'depot', serverName: 'server', stream: 'QA'])
    }

    stage ("Build") {
        build job: 'QA'
    }
}

我不明白我在激励和打包视图方面做错了什么,因为其他视图运行良好。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

如上文David所指出的,请确保您的路线没有领先/

//Get about
router.get('/about', (req,res) => {
    res.render('about');
});

//Get services
router.get('/services', (req,res) => {
    res.render('services');
});

//Get packages
router.get('/packages', (req,res) => {
    res.render('packages');
});

//Get incentives
router.get('/incentives', (req,res) => {
    res.render('incentives');
});

答案 1 :(得分:0)

您需要从/语句中删除开头的res.render...,以获取奖励和打包路线。

希望这会有所帮助!