jade 不在带有参数的路径中显示图像
jade dosen't display image in route with param
我使用的是 expres 4,上传文件夹中有图片
我的密码是
app.use(express.static(__dirname + '/uploads'));
//it works
app.route('/')
.get(function (req, res) {
Post.find({},null,{sort:{'created_at':-1}}).populate('created_by').exec(function(err, posts) {
if (err) throw err;
res.render('blog',{
title: 'Blog',
posts: posts
})
});
});
//it doesn't work
app.route('/post/:id_post')
.get(function (req, res) {
Post.findOne({_id:req.params.id_post}).populate('created_by').exec(function(err, post) {
if (err) throw err;
res.render('detail',{
title: 'Post',
post: post
})
});
});
我的翡翠是
img(src='#{post.image}')
在两个模板中,相同的图像,但是当我访问路线时/
我可以看到图像,当访问/post/:id_post
时我看不到图像
带有前导正斜杠的亲戚 link 从站点 root 开始,而没有它从当前级别开始。
如果您有 link src='image.jpg'
并且它在您的主页 /
页面上,那么 URL 将被提取为 http://example.com/image.jpg
但是,如果相同的 link src='image.jpg'
在某些 /other
页面上,则 URL 被提取为 http://example.com/other/image.jpg(相对于 current (/other) 级别页面)
或者,如果您有 link src='/image.jpg'
(带有 前导正斜杠 ),则 URL 是 始终 获取为 http://example.com/image.jpg(相对于您网站的 root)
我使用的是 expres 4,上传文件夹中有图片
我的密码是
app.use(express.static(__dirname + '/uploads'));
//it works
app.route('/')
.get(function (req, res) {
Post.find({},null,{sort:{'created_at':-1}}).populate('created_by').exec(function(err, posts) {
if (err) throw err;
res.render('blog',{
title: 'Blog',
posts: posts
})
});
});
//it doesn't work
app.route('/post/:id_post')
.get(function (req, res) {
Post.findOne({_id:req.params.id_post}).populate('created_by').exec(function(err, post) {
if (err) throw err;
res.render('detail',{
title: 'Post',
post: post
})
});
});
我的翡翠是
img(src='#{post.image}')
在两个模板中,相同的图像,但是当我访问路线时/
我可以看到图像,当访问/post/:id_post
时我看不到图像
带有前导正斜杠的亲戚 link 从站点 root 开始,而没有它从当前级别开始。
如果您有 link src='image.jpg'
并且它在您的主页 /
页面上,那么 URL 将被提取为 http://example.com/image.jpg
但是,如果相同的 link src='image.jpg'
在某些 /other
页面上,则 URL 被提取为 http://example.com/other/image.jpg(相对于 current (/other) 级别页面)
或者,如果您有 link src='/image.jpg'
(带有 前导正斜杠 ),则 URL 是 始终 获取为 http://example.com/image.jpg(相对于您网站的 root)