模型看起来像
class Cars(models.Model):
name = models.CharFidle(max_length=255)
price = models.DecimalField(max_digits=5,decimal_places=2)
photo = models.ImageField(upload_to='images/cars')
def __unicode__(self):
return self.name
设置
^{pr2}$但当我在这样的模板中使用它时
{% for car in cars %}
<li>{{ car.name }}</li>
<li>{{ car.price }}</li>
<a>{{ car.photo }}</a>
<img src="{{ car.photo.url }}"/>
{% endfor %}
我拿不到图像,怎么了?在
如果有人帮我,那就太好了
将此添加到我的根目录网址.py记住在根中网址.py
从你的设置.py我假设您在基本目录中创建了一个介质文件夹。如果你有,那你就走对了。我想问题出在你的模板上。在
试试这个:
在扩展基之后,不要忘记在模板的顶部包含
{% load staticfiles %}
。。你准备好了。。。在这里可能会发生一些事情:
相关问题 更多 >
编程相关推荐