【发布时间】:2017-07-10 09:07:32
【问题描述】:
我有这个等级:
-mega_series
-mega_series
-series
-models.py
-views.py
...
-manage.py
-media
-covers
-static
MEDIA_URL 和 MEDIA_ROOT 如下:
MEDIA_ROOT = '/Users/lechucico/Documents/mega_series/media/'
MEDIA_URL = 'media/'
在我这样存储图像的模型上:
class Serie (models.Model):
serie_cover = models.ImageField(upload_to='covers')
serie_name = models.CharField(max_length=100)
通过管理站点上传的图像正确地转到路径:mega_series/media/covers/
这就是我通过 html 访问它的方式:
<img src="{{serie.serie_cover.url}}" width="150" height="250" />
我得到的结果网址如下:
为什么图片没有出现在 html 中?
谢谢。
【问题讨论】:
-
settings.py 中的 MEDIA_ROOT 和 MEDIA_URL 是什么
-
尝试使用
serie.serie_cover.url -
@Niyojan - 可能想把它作为答案,因为这是最可能的原因
-
@Niyojan 我没有 MEDIA_ROOT 和 MEDIA_URL。 serie.serie_cover.url 产生相同的结果。
标签: django image django-models