【问题标题】:Express JS not rendering jade templateExpress JS 不渲染翡翠模板
【发布时间】:2012-10-11 22:47:19
【问题描述】:

我将保持简短,我只是尝试使用 express js 渲染一个玉模板。 我正在使用 express 3.0.0rc5 和jade 0.27.6。

这是我的玉石模板,布局:

// test-layout.jade
doctype 5
html
  head
    title My title
    block head
  body
    #content
      block content

还有索引:

// test-index.jade
extends test-layout

block head
  script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js")

block content
  h1 My page

以下是 app.js 的一些摘录:

var app = express();
// Configuration
app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

app.get('/test-jade', function(req, res) {
    res.render('test-index', {}, function(err, html) {
    });
  });
app.get('/test', function(req, res) {
  res.send('this works');
});

现在,每当我尝试转到 http://myurl.com/test-jade 时,浏览器都会挂起并超时,而不会在控制台中显示任何输出(即使我处于开发模式)。

但是,当我转到 http://myurl.com/test 时,我看到“这很有效”。

我觉得我在这里遗漏了一些非常简单的东西,我目前正在从 2.5 升级到 3.0。

如果有人有建议,请提前感谢。

【问题讨论】:

    标签: node.js pug express


    【解决方案1】:

    是空白回调吗?

     res.render('test-index', {}, function(err, html) {
     });
    

    在我正在使用的应用中

    res.render('test-index', {});
    

    【讨论】:

    • 为将来发现此内容的任何人添加评论。我有一个类似的问题,只是把 res.render('test-index', {}) 没有解决它。我不得不使用回调方法来写入数据。
    • res.render('test-index')test-index 相对于什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-17
    • 2012-12-17
    • 1970-01-01
    • 2013-08-05
    • 2015-04-11
    • 2014-11-30
    • 2016-08-04
    相关资源
    最近更新 更多