【发布时间】:2021-04-22 14:39:45
【问题描述】:
Models.py
class Coche(models.Model):
matricula = models.CharField(max_length=7,primary_key=True)
Views.py
class Index(ListView):
model = Coche
total_coches = Coche.objects.filter(reserved=False, sold=False)
模板
<span class="text-primary">{{ total_coches.count }}</span> <span>coches disponibles</span></span>
### 它不显示我的应用程序拥有的汽车数量。有谁知道故障是什么? ###
【问题讨论】:
-
views.py 文件有 template_name = index.html。
-
以total_coches 的名义,我猜你想要该行中的coches 数。那么为什么不直接在视图中的同一行中获取计数呢?
标签: python django templates view count