a=Employee.objects.all().first() b=Employee.objects.all().last() for i in range(a.id,b.id+1): lat = Employee.objects.get(id=i) if(lat.status==True): mailid=lat.email
for i in range(a.id,b.id+1): AttributeError: 'NoneType' object has no attribute 'id'