Django serializer returns empty list

I have a class-based view that returns all the data in the table. But while accessing the URL all I get is an empty list.

models.py

from django.db import models

class EmployeeModel(models.Model):
    EmpID = models.IntegerField(primary_key=True)
    EmpName = models.CharField(max_length=100)
    Email = models.CharField(max_length=100)
    Salary = models.FloatField()

    class Meta:
        verbose_name = 'employeetable'

views.py

from rest_framework.views import APIView
from rest_framework.response import Response
from .models import EmployeeModel
from .serializers import EmployeeSerialize

class EmployeeTable(APIView):

    def get(self,request):
        emp_obj = EmployeeModel.objects.all()
        empserializer = EmployeeSerialize(emp_obj,many=True)
        return Response(empserializer.data)

serializers.py

from rest_framework import serializers
from .models import EmployeeModel

class EmployeeSerialize(serializers.ModelSerializer):
    class Meta:
        model = EmployeeModel
        fields = '__all__'

urls.py

from django.contrib import admin
from django.urls import path, include
from .views import EmployeeTable, transformer_list

urlpatterns = [
    path('display/',EmployeeTable.as_view()),
]

The table has 5 rows. It is not empty. I want to serialize all 5 rows

I have also created the same but in my case, it worked see the below images

enter image description here

See my serializer

enter image description here

See my models below

enter image description here

and my output is here below

enter image description here

I think there are some issue at your code or some mistake can be there can you please provide full information

Back to Top