我看了官方的api文档,但还是有点不明白,希望大家能够给我通俗点的解释,谢谢^_^
天蓬老师2017-04-17 13:23:56
What the document says is actually pretty good
Think of app.render() as a utility function for generating rendered view strings. Internally res.render() uses app.render() to render views.
treats app.render
as a tool for generating views, and res.render
also calls app.render
internally.
The difference is this, app.render
is only responsible for generating the view. You will find that it is not capable of responding to the view to the client (browser). Only res.render
has the response
object in hand and can respond to the view. to the client.
res.render
can be seen as follows:
res.render = function(view, locals, cb){
app.render(view, locals, function(err, html){
if(typeof cb !== 'undefined'){
return cb(err, html);
}
res.send(html);
});
};