我正在通过multer将图像上传到./public/images ...它上传得很好,我可以在文件夹中找到它,也可以在正确关联的数据库中看到它...
这是邮寄路线:
exports.postRevive = (req, res, next) => {
var reviveShowName = req.body.reviveShowName;
var reviveGoal = req.body.reviveGoal;
var reviveTitle = req.body.reviveTitle;
var reviveVideo = req.body.reviveVideo;
var reviveStory = req.body.reviveStory;
var reviveCategory = req.body.reviveCategory;
var revivePhoto = req.file.filename;
var author = {
id: req.user._id,
username: req.user.name
};
var newRevive = {reviveShowName: reviveShowName, reviveGoal: reviveGoal, reviveTitle: reviveTitle, revivePhoto: revivePhoto, reviveVideo: reviveVideo, reviveStory: reviveStory, author: author, reviveCategory: reviveCategory};
Revive.create(newRevive, function(err, newlyCreatedRevive) {
if(err) {
console.log(err);
} else {
res.redirect('/');
}
});
};
然后我查询数据库并将所有内容传递给home.pug和home.pug我试图显示它:
以下是home.pug的代码:
if revives
each revive, i in revives
.clearfix
a.slide.revive(href='#')
.media
img(src='/images/#{revive.revivePhoto}')
.funding
h2 $12,151 of #{revive.reviveGoal}
.funds
.fund-bar
.progress-bar(style='width:82%')
span.favorite
.copy
p.secondary 8.7/10 • Animation, Comedy
h3.ellipsis
h4=revive.reviveTitle
= revive.reviveTitle显示,#{revive.reviveGoal}显示...图片没有,我无法弄清楚为什么......
答案 0 :(得分:0)
显然,唯一的错误是.pug语法。我使用的是.jade语法,但.pug略有不同
而不是img(src='/images/#{revive.revivePhoto}')
应为img(src='/images/'+revive.revivePhoto)
哈巴狗/玉石中为数不多的微妙变化之一...