【发布时间】:2019-08-10 08:54:21
【问题描述】:
我想将一个变量从 Express 发送到 Pug。
因此我已经发现我必须使用 res.render(),但是如果我尝试这个,我只会得到一个未定义的变量。
在我的 index.js 中:
app.post("/example", upload.single("photo"), (req, res) => {
{... some code}
var html = "some text";
res.render("results", {
html: html
});
在我的 results.pug 中,我尝试将文本显示为字符串:
p "#{html}"
目前我的页面上只有两个“”。 但我需要显示结果
感谢您的帮助!!!! :)
【问题讨论】:
-
您是否设置了渲染引擎(正确)?类似
app.set('view engine', 'pug') -
我已经向 pug 发送了以下信息:
const resultsTemplate = pug.compileFile("public/results.pug")并发送了一些信息:res.send(resultsTemplate({ image: base64String })),但这不适用于变量...
标签: javascript express pug