为什么我会收到损坏的图像图标?
Why am I getting a broken image icon?
我正在尝试在 ejs 页面上显示数据库中的所有图像。我将他们的 URL 保存到 post table。 ejs 页面当前显示损坏的图像图标。这些有什么问题吗?我需要遍历它们吗? IMG URLs 存储在名为 posts
的 table 中
下面是一个示例 url 图片:
https://res.cloudinary.com/zfinnan/image/upload/v1607108641/q4kyfxxkbf5waxgcrznd.png
这是我的路线:
app.get('/', (req, res) => {
db.post.findAll()
.then((posts) => {
const postArray = posts.map(post => {
return post.get();
})
res.render('index', { image: post.image_url });
})
});
这是我的 index.ejs 页面:
<img width="500px" height="500px" src="<%= image %>" alt="uploaded image">
你的 post
对象在 posts
循环之外不存在,你需要处理这个,你可以将渲染放在 posts.map
中或者你可以使用你的 postArray
获取图像URL渲染图像
app.get('/', (req, res) => {
db.post.findAll()
.then((posts) => {
const postArray = posts.map(post => {
return post.get();
})
// I am assuming you need only one and the first post instance contains that image URL
res.render('index', { image: postArray[0].image_url });
})
});
我正在尝试在 ejs 页面上显示数据库中的所有图像。我将他们的 URL 保存到 post table。 ejs 页面当前显示损坏的图像图标。这些有什么问题吗?我需要遍历它们吗? IMG URLs 存储在名为 posts
的 table 中下面是一个示例 url 图片:
https://res.cloudinary.com/zfinnan/image/upload/v1607108641/q4kyfxxkbf5waxgcrznd.png
这是我的路线:
app.get('/', (req, res) => {
db.post.findAll()
.then((posts) => {
const postArray = posts.map(post => {
return post.get();
})
res.render('index', { image: post.image_url });
})
});
这是我的 index.ejs 页面:
<img width="500px" height="500px" src="<%= image %>" alt="uploaded image">
你的 post
对象在 posts
循环之外不存在,你需要处理这个,你可以将渲染放在 posts.map
中或者你可以使用你的 postArray
获取图像URL渲染图像
app.get('/', (req, res) => {
db.post.findAll()
.then((posts) => {
const postArray = posts.map(post => {
return post.get();
})
// I am assuming you need only one and the first post instance contains that image URL
res.render('index', { image: postArray[0].image_url });
})
});