2015년 1월 6일 화요일

Failed to lookup view

I am beginner to node.js. I am working with an example here with and I am using 'handlebars'. But I am unable to load view of pages. I have kept my pages inside views folder but I am not able to see results.

I am getting error.

Error: Failed to lookup view "500" in views directory "d:\projects\meadowlark\site\views"
   at EventEmitter.app.render (d:\projects\meadowlark\site\node_modules\express\lib\application.js:519:17)
   at ServerResponse.res.render (d:\projects\meadowlark\site\node_modules\express\lib\response.js:904:7)
   at d:\projects\meadowlark\site\meadowlark.js:29:7
   at Layer.handle_error (d:\projects\meadowlark\site\node_modules\express\lib\router\layer.js:58:5)
   at trim_prefix (d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:269:13)
   at d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:238:9
   at Function.proto.process_params (d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:313:12)
   at d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:229:12
   at Function.match_layer (d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:296:3)
   at next (d:\projects\meadowlark\site\node_modules\express\lib\router\index.js:190:10)

Please help me regardng this to solve it.

My js code is as follows:
var express = require('express');
var app = express();
// set up handlebars view engine
var handlebars = require('express3-handlebars')
.create({ defaultLayout:'main' });
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');

app.set('port',process.env.port || 3000);

app.get('/', function(req, res) {
res.render('home');
});

app.get('/about', function(req, res) {
res.render('about');
});

// 404 catch-all handler (middleware)
app.use(function(req, res, next){
res.status(404);
res.render('404');
});

// 500 error handler (middleware)
app.use(function(err, req, res, next){
console.error(err.stack);
res.status(500);
res.render('500');
});

app.listen(app.get('port'),function(){
console.log('Express started on http://localhost: '+ app.get('port') + " Press CTRL+C to terminate.");
});



> I am beginner to node.js. I am working with an example here with and I am using 'handlebars'. But I am unable to load view of pages. I have kept my pages inside views folder but I am not able to see results.
>
> I am getting error.
>
> Error: Failed to lookup view "500" in views directory "d:\projects\meadowlark\site\views"
It seems that an error has occurred in your application, and in the process of trying to show you the error message, a second error occurred, namely that it could not find the error page.

Since it says it could not find a file called "500" in the directory "d:\projects\meadowlark\site\views", my first question would be: is there a file called "500" in the directory "d:\projects\meadowlark\site\views"? If not, make one with the correct contents.

I don't know whether the template engine you're using requires you to use an extension on those template filenames, and if so what that extension is, or whether it requires you to use no extension.



It have those files on the particular locations in views folder, As shown in the error. But still I dont know why this error is occuring.
I am using handlebars template engine and its extension is extension is ".hbs" or  ".handlebars". And I think  res.render() is not working with this extension. Yes handlebars requires to use the extension.



It seems like you're missing 500.handlebars (or maybe .hbs) error message in "d:\projects\meadowlark\site\views".

Do you have a 500.* file anywhere in your app? If yes, did you point your views directory somewhere else then default? If yes, maybe put a 500.handlebars in the views/ dir.

If not, lookup somewhere on the net for an example or to be quick about it, put this in d:\projects\meadowlark\site\views\500.handlebars:

<div>{{error}}</div>


Then, as Ryan here says, you'll have to find your actual error, but that's another question :)


댓글 없음:

댓글 쓰기