我在EJS中打印错误有问题,因为当我在ejs<%= errors%>中使用时我被发送到找不到错误404。有人能告诉我它是如何打印出来的吗?
req.checkBody('login', 'Login is required').notEmpty();
req.checkBody('password', 'Password is required').notEmpty();
var errors = req.validationErrors();
if (errors) {
console.log(errors)
res.render('index', {
errors: errors
});
答案 0 :(得分:1)
你需要先初始化错误。例如:索引页的get方法中的res.render('index'),{errors: null});
。