【发布时间】:2021-05-23 13:15:34
【问题描述】:
我试图在这里寻找答案,但到目前为止没有任何效果,关于车把的话题也不多。 我正在努力让图像显示在我的节点应用程序上。
我在 app.js 上有这个,下面是我试图让图像显示在 .hbs 文件中的代码:
const express = require("express");
const path = require("path");
const hbs = require("hbs");
const app = express();
const bodyParser = require("body-parser");
const port = process.env.PORT || 80;
require("./db/conn");
const SwimmingCollection = require("./models/schema");
const static_path = path.join(__dirname, "../public");
const template_path = path.join(__dirname, "../templates/views");
const partials_path = path.join(__dirname, "../templates/partials");
app.use(express.static(static_path));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({ extended: true }));
app.set("view engine", "hbs");
app.set("views", template_path);
hbs.registerPartials(partials_path);
app.get("/", (req, res) => {
res.render("index");
});
app.listen(port, () => {
console.log(`Listening to the port at ${port}`);
});
如何解决这个问题?
【问题讨论】:
-
您的图片在您的公共文件夹中吗?
-
是的,在公共文件夹中我创建了图像文件夹。所有图像都在图像文件夹内
-
我认为您应该显示请求图片的 URL。
标签: html css node.js express handlebars.js