如何使用Django打印HTML中的所有查询集信息

时间:2019-04-02 10:04:02

标签: django-templates

我在Django中设置了一些查询 **查看。 py **

u_info = User.objects.filter(username=user)
h_info = hostel.objects.filter(u_id=user)
i_info= Image.object.filter(u_id=user)
f_info= Facility.objects.filter(u_id=user)
a_info = alluser . objects.filter(user=user)
context = {'u_info': u_info, 'h_info': h_info, 'i_info': i_info, 'f_info': 
f_info,'a_info':a_info}
return render(request, " som .html",context)

**模型。 py **

class Facility(models.Model):

def __str__(self):
    return self.u_id

u_id = models . ForeignKey (User, on_delete=models.CASCADE)
f_name= models . CharField(max_length=15, blank=True)
f_detail= models .TextField(max_length=200, blank=True)
f_Price= models .DecimalField(decimal_places=0, max_digits=6, blank=True, null=True)

objects = models.Manager()

所以我该如何在html中打印所有功能

some.html

<body>
  {% if f_info %}
      **print all information of facility**
      <p>{{f_info}}</p>
  {% end if %}
</body>

0 个答案:

没有答案