mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 634 forks source link

Template Not Found #1431

Open Nani2777 opened 1 year ago

Nani2777 commented 1 year ago

I have been trying to run my demo site and was able to run it successfully from the current directory but after configuring the service file in systemd was unable to run it.

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

app.set('views', path.join(__dirname, 'views')); app.set("view engine", "nunjucks");

app.use("/public", express.static(dirname + "/public")); app.use("/", express.static(dirname + "/"));

app.get(["/","/index","/index.html"], (req, res) => { data.base_file = __dirname + '/views/base_file.njk'; res.render(__dirname + "/views/index.njk", data); })`

And Directory structure as follows Screenshot from 2023-01-20 14-28-07

Below is the Error Screenshot Screenshot from 2023-01-20 14-37-06

Can someone please help

hrydi commented 1 year ago

i'am facing the same issue, but now already fixed it. this is my setup:

const viewpath = path.join(__dirname, './views')
const nnjk = require('nunjucks')
nnjk.configure(viewpath, {
  autoescape: true,
  express: app,
})
app.set('views', viewpath)
app.set('view engine', 'html')

just set your view path equal to express views hope this would help,