使用Pug模板时出现意外的标记“缩进”

时间:2017-11-21 07:05:45

标签: node.js pug pugjs

我有一个应该输出小内容的简单应用程序。我使用 NodeJs,Express和Pug

**\*.trx

我的Pug文件/ HTML

const pug = require('pug');
const express = require('express');
const app = express();

const indexFile = 'index'; // the file to load

app.set('view engine', 'pug'); // use pug

app.get('/', function (req, res) {
  res.render(indexFile, {content: 7}); // load the file and set the variable to 7
});

app.listen(8888, function () {
  console.log('Server running on port 8888');
});

启动服务器时收到此错误消息

doctype html
    link(rel='stylesheet', href='../CSS/requirements.css')
    script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js')
    body
      p = content

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:4)

我认为您在html之后忘了doctype html

doctype html
html
  link(rel='stylesheet', href='../CSS/requirements.css')
  script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js')
  body
    p=content

doctype htmlhtml应处于相同的意图级别。顺便说一句,将p = content更改为p=content以打印传递值