Django预取_相关无法将数据传递到模板

Django预取_相关无法将数据传递到模板,django,django-templates,Django,Django Templates,我有两款Django车型: class Product(models.Model): name = models.CharField(max_length=80, null=True) is_active = models.BooleanField(default=False, null=False) class Image(models.Model): url = models.CharField(max_length=255, unique=True, null=F

我有两款Django车型:

class Product(models.Model):
    name = models.CharField(max_length=80, null=True)
    is_active = models.BooleanField(default=False, null=False)

class Image(models.Model):
    url = models.CharField(max_length=255, unique=True, null=False)
    product = models.ForeignKey('Product', related_name='images')
我有一套特定的产品。每个产品都有多个图像。最初的调用类似于:

product_list = product_list.filter(is_active=True).prefetch_related('images')
然后,根据应用的过滤器,产品列表将被缩减

当我尝试在显示层(模板)中使用产品列表时,我迭代产品列表。我可以访问除图像以外的所有产品字段

{{product.images.0.id}==>empty

{{product.images}}=>返回Image.None


通过调试器运行代码,我可以看到正在执行的图像SQL查询,只是没有任何数据传递到模板。那里肯定有数据,因为我可以通过我的SQL客户机验证运行它的查询。有人知道为什么会这样吗?如何访问给定产品的图像?

我解决了我的问题。必须访问预取的数据,如:product.images.all.0.id