gpt4 book ai didi

node.js - nunjucks:找不到模板

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

尝试呈现 nunjucks 模板但收到 Error: template not found: email.html

server/
views/
email/
email.html
workers/
email.worker.js
//email.worker.js
function createMessage(articles) {
console.log(__dirname) // /<path>/server/workers

nunjucks.configure('../views/email/');
return nunjucks.render('email.html', articles);
}

不知道这里出了什么问题。

最佳答案

我遇到了同样的问题,我的解决方案是使用路径模块:

const njk = require('nunjucks');

return njk.render(path.resolve(__dirname, '../views/email/' + 'email' + '.html'), articles);

关于node.js - nunjucks:找不到模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39050788/

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