微博例子中, 我很奇怪我为什么都清求不到路径了。Failed to lookup view "login" 我是点击登录请求 view 竟然报错。 注册页是一样写的。都是可以
发布于 2年前 作者 newbingj 1856 次浏览

Express 500 Error: Failed to lookup view “log” at Function.app.render (C:\Users\wd\microblog\node_modules\express\lib\application.js:493:17) at ServerResponse.res.render [as partial] (C:\Users\wd\microblog\node_modules\express\lib\response.js:753:7) at ServerResponse.module.exports.res.render (C:\Users\wd\microblog\node_modules\express-partials\index.js:55:9) at C:\Users\wd\microblog\routes\index.js:16:6 at callbacks (C:\Users\wd\microblog\node_modules\express\lib\router\index.js:161:37) at param (C:\Users\wd\microblog\node_modules\express\lib\router\index.js:135:11) at pass (C:\Users\wd\microblog\node_modules\express\lib\router\index.js:142:5) at Router._dispatch (C:\Users\wd\microblog\node_modules\express\lib\router\index.js:170:5) at Object.router (C:\Users\wd\microblog\node_modules\express\lib\router\index.js:33:10) at next (C:\Users\wd\microblog\node_modules\express\node_modules\connect\lib\proto.js:199:15)

/routes/index.js app.get('/log’, function(req, res) { res.render('log’, { title: '用户登入’, }); });

app.post('/log’, function(req, res) {

});

app.js

/**

  • Module dependencies. */ var express = require(‘express’) , routes = require(‘./routes’) , user = require(‘./routes/user’) , http = require(‘http’) , path = require(‘path’);

var flash = require(‘connect-flash’); var partials = require(‘express-partials’); var MongoStore = require(‘connect-mongo’)(express); var settings = require(‘./settings’); var app = express();

var util = require(‘util’)

app.configure(function(){ app.set('port’, process.env.PORT || 3001);

//设置页面模板和引擎模板的位置 app.set('views’, __dirname + ‘/views’); //视图文件目录 app.set('view engine’, ‘ejs’); //视图模板引擎 app.use(partials()); //通过user启用中间件 app.use(express.favicon()); app.use(express.logger(‘dev’)); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser()); //Cookie 解析中间件 app.use(flash()); app.use(express.session({ secret:settings.cookieSecret, store:new MongoStore({ //保存回话到数据库 db:settings.db }) }));

app.use(function(req,res,next){  
res.locals.user = req.session ? req.session.user:'';  
res.locals.keyword = req.session ? req.session.keyword:'';  

var err = req.flash('error');
    if(err.length){
        res.locals.error =  err;
    }else{
        res.locals.error =  null;
    }

    var success = req.flash('success');
    if(success.length){
        res.locals.success =  req.flash('success');
    }else{
        res.locals.success =  null;
    }

next();  

});

app.use(app.router); app.use(express.static(path.join(__dirname, ‘public’))); //表示提供了静态文件支持

});

app.configure('development’, function(){ app.use(express.errorHandler()); });

//定义动态视图工具 获取及时信息 //app.dynamicHelpers({ // //获取用户信息 // user:function(req,res){ // return user.session.user; // },error:function(req,res){ //
// }, // success:function(req,res){ // var sucess = req.flash(‘success’); // if(success.length){ // return success; // }else // return null; // } //
//});

routes(app);//这个是新加的 //routes/index.js 路由文件,用于组织展示内容 http.createServer(app).listen(app.get(‘port’), function(){ console.log("Express server listening on port " + app.get(‘port’)); });

2 回复

自己真SB, 忘记写视图了。

哈哈哈哈哈 我也犯这个毛病来的

回到顶部