gpt4 book ai didi

node.js - 使用 Pug 模板时出现意外标记 "indent"

转载 作者:搜寻专家 更新时间:2023-10-31 23:07:44 24 4
gpt4 key购买 nike

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

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');
});

还有我的 Pug 文件/HTML

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

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

Error: C:\Users\mah\Desktop\Test\views\index.pug:2:1
1| doctype html

> 2| link(rel='stylesheet', href='../CSS/requirements.css')

-------^
3| script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js')

4| body

5| p = content


unexpected token "indent"
at makeError (C:\Users\mah\Desktop\Test\node_modules\pug-error\index.js:32:13)
at Parser.error (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:53:15)
at Parser.parseExpr (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:264:14)
at Parser.parse (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:112:25)
at parse (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:12:20)
at Object.parse (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:126:22)
at Function.loadString [as string] (C:\Users\mah\Desktop\Test\node_modules\pug-load\index.js:45:21)
at compileBody (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:86:18)
at Object.exports.compile (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:243:16)
at handleTemplateCache (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:216:25)

有人可以帮我吗?

最佳答案

我想你在 doctype html 之后忘记了 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 以打印传递的值

关于node.js - 使用 Pug 模板时出现意外标记 "indent",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47407141/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com