Django Viewset Has Not Attribute 'Get_Extra_Actions'

Django viewset has not attribute 'get_extra_actions'

You've called it a viewset, but that doesn't make it one; you inherit from APIView which is a standalone generic view, not a viewset.

A viewset needs to inherit from viewsets.ViewSet.

Django REST framework: type object X has no attribute 'get_extra_actions'

Basically you are trying to register a non-viewset(here InstanceList a view, not a viewset) to router. Instead of this, you can simply use it in urls like this:

router = routers.DefaultRouter()
router.register(r'users',views.UserViewSet)

urlpatterns = [
path('', views.dash, name='dash'),
path('api/', include(router.urls)),
path('api/instances/', views.InstanceList.as_view(), name="instances"),
]

Django Rest Framework - AttributeError: 'function' object has no attribute 'get_extra_actions'

It's a typo:


def PropertiesViewSet(ModelViewSet):
queryset = Property.objects.all()
serializer_class = PropertySerializer


# Should be class

class PropertiesViewSet(ModelViewSet):
queryset = Property.objects.all()
serializer_class = PropertySerializer

AttributeError: type object has no attribute 'get_extra_actions'

You cannot add generic Views in routers

So remove this line

router.register(r'userplatforms/', views.UserPlatformList, 'userplatforms')

and update urlpatterns to

urlpatterns = [
path('userplatforms/', views.UserPlatformList, name='userplatforms'),
path("^", include(router.urls))
]

Django Rest Framework - Attribute Error: 'function' has no attribute 'get_extra_actions'

You need to remove @api_view it is not compatible with viewset for manage http methods which you want use you should use http_method_names attribute:

class LibrarynViewSet(viewsets.ViewSet):

http_method_names = ['get',]

RetrieveAPIView generated a error 'function' object has no attribute 'get_extra_actions'

Instead of inheriting APIView you have to inherit a ViewSet.

These changes must work for you,

views.py =>

from rest_framework.viewsets import GenericViewSet
from rest_framework.mixins import RetrieveModelMixin
from ..models import *
from .serializers import *

class DespachoDetail(GenericViewSet, RetrieveModelMixin):
queryset = Despacho.objects.all()
serializer_class = DespachoSerializer()

urls.py =>

from django.urls import include, path
from rest_framework import routers
from .views import *

router = routers.DefaultRouter()
router.register(r'^despacho/<int:pk>', DespachoDetail, basename='despacho-detail')
urlpatterns = router.urls


Related Topics



Leave a reply



Submit