我有以下models.py:
class Insurance(models.Model):
area = models.CharField(max_length=100)
title = models.CharField(max_length=50)
insurance_type = models.CharField(max_length=50)
area_photo = models.ImageField(upload_to='static/image')
这个模板:
{% for product in insurance.insuranceproducts_set.all %}
<li class="one_third btmspace-10 holder">
<figure><img src="{% static 'img/320x320.png' %}" alt="">
<div class="content">
<p><a href="{% url 'insurance:farmer_type' product.id %}">{{ product.title }}</a></p>
</div>
</figure>
</li>
{% endfor %}
问题是页面需要加载有关产品的简短描述。这里 它需要加载与该保险产品相关的图像。我该怎么办?
答案 0 :(得分:0)
文档中有一个不错的摘要:https://docs.djangoproject.com/en/2.1/faq/usage/#how-do-i-use-image-and-file-fields
尝试将图像标签更改为::
<img src="{{insurance.area_photo.url}}" alt="">