我有一个django应用程序,允许用户使用它提交图像。现在我的模型看起来像在Django中显示图像
class Posting(models.Model):
title = models.CharField(max_length=150)
images = models.ForeignKey(Image, null=True)
class Image(models.Model):
img = models.ImageField(upload_to="photos/",null=True, blank=True)
而我试图在我的模板中显示图像,但我似乎无法得到它的工作。我已经去了无数堆栈溢出帖子,并没有任何运气。在我的模板中,我有
{ for post in postings }
<img src"{{ post.image.url }} #and many variations of this
但是其他似乎显示的网址。该网址似乎总是空白。任何帮助将不胜感激!
试试这个 -
因为你发布模型有 '图像' 命名的图像模型的属性。 –
ancho
2015-03-31 05:19:25
'
'试试这个。我想问题是相对路径。追加'/'到路径。 –
2015-03-31 05:30:43