Python django循环通过模型字段
可能重复:Python django循环通过模型字段,python,django,Python,Django,可能重复: 我有下一个型号: class People(models.Model): name = models.CharField(max_length=100) lastname = models.CharField(max_length=100) 我想循环浏览People表中的所有项目 In views.py -当我尝试这个时: for each in People().objects.all(): name=each.name for each i
我有下一个型号:
class People(models.Model):
name = models.CharField(max_length=100)
lastname = models.CharField(max_length=100)
我想循环浏览People表中的所有项目
In views.py
-当我尝试这个时:
for each in People().objects.all():
name=each.name
for each in People():
name=each.name
我得到了这个错误:
Manager isn't accessible via People instances
-当我尝试这个时:
for each in People().objects.all():
name=each.name
for each in People():
name=each.name
我得到这个错误:
'People' object is not iterable
我如何解决这个问题,以及如何循环浏览我的人员表中的所有项目 People.objects.all()
它对类而不是实例People
notPeople()