nodejs表示未知方法渲染

时间:2012-05-03 22:08:09

标签: node.js express

创建普通的vanilla express应用程序后,我有这个默认的app.js:

var express = require('express');
var app = module.exports = express.createServer();

// Configuration
app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser());
  app.use(express.session({ secret: 'your secret here' }));
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

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

// Routes
app.get('/', function(req, res) {
  res.render('index', { title: 'Foo' }) // 34:7 is the .render
});

app.listen(3000, function(){
  console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});

但是我继续得到这个堆栈跟踪:

500 SyntaxError: Unexpected identifier
...
at C:\Users\...\app.js:34:7

就在'/'route

的render方法之前

layout.jade看起来像这样:

!!!
html(lang='de')
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    link(rel='shortcut icon' type='image/png' href='/images/favicon.png')
    script(src='/javascripts/jquery-1.7.1.min.js' type='text/javascript' charset='utf-8')
  #header!= partial('header.jade')
  body!= body
  #footer!= partial('footer.jade')

和index.jade看起来像这样:

#body

  #nav
    a(href='/login') anmelden

我错过了什么?

1 个答案:

答案 0 :(得分:2)

尝试更改此内容:

link(rel='shortcut icon' type='image/png' href='/images/favicon.png')
script(src='/javascripts/jquery-1.7.1.min.js' type='text/javascript' charset='utf-8')

到此:

link(rel='shortcut icon', type='image/png', href='/images/favicon.png')
script(src='/javascripts/jquery-1.7.1.min.js', type='text/javascript', charset='utf-8')

看一下逗号!