简体   繁体   English

Nunjucks - 错误:找不到模板:

[英]Nunjucks - Error: template not found:

The template exists exactly where it's supposed to and the path.join is pointed directly to it.模板正好存在于它应该存在的位置,并且path.join直接指向它。 Yet still getting a Error: template not found: .但仍然收到Error: template not found: Also tried using path.resolve but gives the same error.也尝试使用path.resolve但给出了相同的错误。 Incidentally I'm using exactly the same structure in another file and it works without any problems.顺便说一句,我在另一个文件中使用了完全相同的结构,它可以正常工作。 Any ideas?有什么想法吗? Cheers!干杯!

var deferred = q.defer();
nunjucks.render(path.join(__dirname, 'form.html'), {
          form: extraStuff
        }, function (err, html) {
          if (err) {
            console.log('Nunjucks returns error here....');
            return deferred.reject(err);
          }
          console.log('RENDERING....');
          deferred.resolve(html);
        });

Do you have configured nunjucks like below?你有没有像下面这样配置 nunjucks?

nunjucks.configure('views')

Then nunjucks searches templates relative to this path (views).然后 nunjucks 搜索与此路径相关的模板(视图)。

Hi everyone i have some easy code in beginning backend nodeJS. 大家好,我在开始后端nodeJS时有一些简单的代码。 I get first my backend error ))) 我首先得到后端错误)))

const express = require("express"); const app = express(); const nunjucks = require("nunjucks"); const path = require("path");

var views = path.join(__dirname, "..", "./client");

nunjucks.configure("views", { autoescape: true, express: app });

app.get("/", (req, res) => { res.render("index.html", { date: new Date() }); });

app.listen(7777, () => { console.log("Server started on port 7777"); });

Why i get this error: 为什么我收到此错误:

Error: template not found: index.html 错误:找不到模板:index.html

Thankś for advanced. 感谢高级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM