关于handlebars模板后缀名

Author Avatar
Aryb1n 11月 01, 2016

express使用模板引擎handlebars时候,默认模板的后缀为#.handlebars#,发现直接替换了handlebars传入对象中的extname,仍然会报错

Failed to lookup view "home" in views directory "/home/***/projectName/views"

报错代码

var express = require('express');
var handlebars = require('express3-handlebars')
  .create({defaultLayout: 'main', extname: '.hbs'});


var app = express();
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');

后来发现。。。居然同时还要写成这样子。。才可以

var express = require('express');
var handlebars = require('express3-handlebars')
  .create({defaultLayout: 'main', extname: '.hbs'});


var app = express();
app.engine('hbs', handlebars.engine);
app.set('view engine', 'hbs');