AttributeError: type object 'CustomerListAPIViewSet' has no attribute 'get_extra_actions'

163 views
Skip to first unread message

Asaduzzaman Sohel

unread,
May 10, 2020, 4:35:57 AM5/10/20
to Django REST framework
I got an error when I run my Django app on my local pc.


 File "/home/asad/PycharmProjects/microshop/venv/lib/python3.8/site-packages/rest_framework/routers.py", line 237, in get_urls
    routes = self.get_routes(viewset)
  File "/home/asad/PycharmProjects/microshop/venv/lib/python3.8/site-packages/rest_framework/routers.py", line 153, in get_routes
    extra_actions = viewset.get_extra_actions()
AttributeError: type object 'CustomerListAPIViewSet' has no attribute 'get_extra_actions'

this is my code

class CustomerListAPIViewSet(generics.ListAPIView):
queryset = Customer.objects.all()
serializer_class = CustomerSerializer



class CustomerSerializer(serializers.ModelSerializer):
class Meta:
model = Customer
fields = ['name', 'phone_number', 'address', ]
url file:
from django.urls import path, include
from accounts_app.views import CustomerListAPIViewSet
from rest_framework import routers

router = routers.DefaultRouter()

router.register(r'customer/', CustomerListAPIViewSet)

urlpatterns = router.urls

Jason

unread,
May 10, 2020, 6:14:16 PM5/10/20
to Django REST framework
You're inheriting from ListAPIView, not ModelViewSet.  Those are two entirely different classes, one is for generic views and the other is for a view set.  

Asaduzzaman Sohel

unread,
May 12, 2020, 4:42:50 AM5/12/20
to Django REST framework
Thank you. I realized that generic view and viewset entirely.
Reply all
Reply to author
Forward
0 new messages