//代码如下 router.post('/reg’, function(req, res) { var name = req.query.name, password = req.body.password, password_re = req.body[‘password-repeat’];
//检验用户两次输入的密码是否一致
if (password_re != password) {
req.flash('error', '两次输入的密码不一致!');
return res.redirect('/reg');//返回主册页
}
错误日志: Error: Failed to lookup view “error” in views directory “D:\WORK\node\mytest\vie ws” at Function.app.render (D:\WORK\node\mytest\node_modules\express\lib\applica tion.js:492:17) at ServerResponse.res.render (D:\WORK\node\mytest\node_modules\express\lib\r esponse.js:802:7) at Layer.module.exports [as handle] (D:\WORK\node\mytest\app.js:67:9) at trim_prefix (D:\WORK\node\mytest\node_modules\express\lib\router\index.js :235:17) at D:\WORK\node\mytest\node_modules\express\lib\router\index.js:208:9 at Function.proto.process_params (D:\WORK\node\mytest\node_modules\express\l ib\router\index.js:269:12) at IncomingMessage.next (D:\WORK\node\mytest\node_modules\express\lib\router \index.js:199:19) at fn (D:\WORK\node\mytest\node_modules\express\lib\response.js:797:25) at Function.app.render (D:\WORK\node\mytest\node_modules\express\lib\applica tion.js:494:14) at ServerResponse.res.render (D:\WORK\node\mytest\node_modules\express\lib\r esponse.js:802:7)
app.js如下 var fs = require(‘fs’); var accessLog = fs.createWriteStream('access.log’, {flags: 'a’}); var errorLog = fs.createWriteStream('error.log’, {flags: 'a’});
var express = require(‘express’); var path = require(‘path’); var favicon = require(‘static-favicon’); var logger = require(‘morgan’); var cookieParser = require(‘cookie-parser’); var bodyParser = require(‘body-parser’);
var routes = require(‘./routes/index’);
var session = require(‘express-session’);
var MongoStore = require(‘connect-mongo’)(session); var settings = require(‘./settings’);
var flash = require(‘connect-flash’); var app = express();
// view engine setup app.set('views’, path.join(__dirname, ‘views’)); app.set('view engine’, ‘ejs’); app.use(flash());
app.use(favicon()); app.use(logger(‘dev’)); app.use(bodyParser.json()); app.use(bodyParser.urlencoded()); app.use(cookieParser()); app.use(express.static(path.join(__dirname, ‘public’)));
//app.use('/’, routes);
routes(app);
app.use(session({ secret:settings.cookieSecret, key:settings.db, saveUninitialized: true, resave: true, cookie:{maxAge:100060602430}, store:new MongoStore({db:settings.db}) })); /// catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error(‘Not Found’); err.status = 404; next(err); });
/// error handlers
// development error handler // will print stacktrace if (app.get(‘env’) === ‘development’) { app.use(function(err, req, res, next) { res.status(err.status || 500); res.render('error’, { message: err.message, error: err }); }); }
// production error handler // no stacktraces leaked to user app.use(function(err, req, res, next) { res.status(err.status || 500); res.render('error’, { message: err.message, error: {} }); });
module.exports = app;
的确像你说的那样,是找不到ERROR这个VIEW,但FLASH这个模块根本不需要用到这个VIEW啊,错误就发生在req.flash()这句 错误日志: Error: Failed to lookup view “error” in views directory “D:\WORK\node\mytest\vie ws” at Function.app.render (D:\WORK\node\mytest\node_modules\express\lib\applica tion.js:492:17) at ServerResponse.res.render (D:\WORK\node\mytest\node_modules\express\lib\r esponse.js:802:7) at Layer.module.exports [as handle] (D:\WORK\node\mytest\app.js:67:9) at trim_prefix (D:\WORK\node\mytest\node_modules\express\lib\router\index.js :235:17) at D:\WORK\node\mytest\node_modules\express\lib\router\index.js:208:9 at Function.proto.process_params (D:\WORK\node\mytest\node_modules\express\l ib\router\index.js:269:12) at IncomingMessage.next (D:\WORK\node\mytest\node_modules\express\lib\router \index.js:199:19) at fn (D:\WORK\node\mytest\node_modules\express\lib\response.js:797:25) at Function.app.render (D:\WORK\node\mytest\node_modules\express\lib\applica tion.js:494:14) at ServerResponse.res.render (D:\WORK\node\mytest\node_modules\express\lib\r esponse.js:802:7)