Skip to content Skip to sidebar Skip to footer

Printing Multiple Items Using Serializer

@api_view(['GET']) def selected_device(request,pk=None): if pk != None: devices = Device.objects.filter(pk=pk) devicedetail = DeviceDetail.objects.filter(DD2DKE

Solution 1:

You write

for i in interfaces:
    data = [{"interface": i}]

which means you keep on overwriting data with a new value. I think you want:

data = []
for i in interfaces:
    data.append({"interface": i})

or more simply

data = [{"interace": i} for i in interfaces]

Post a Comment for "Printing Multiple Items Using Serializer"