app.use(function(req, res, next){
console.log('error:' + req.flash('error').toString());
res.locals.error = req.flash('error').toString();
console.log('locals error:' + res.locals.error);
next();
});
这里面取不到值,赋值的时候可以取到
router.post('/', function (req, res, next) {
var name = req.body.name;
if (name.length > 0) {
new category({ name: name }).save(function (err) {
res.send('succ');
});
}
else {
req.flash('error', 'category length need 1 lest');
//console.log(req.flash('error').toString());
res.redirect('back');
}
});
这个怎么解决