Django viewset has not attribute 'get_extra_actions'

前端 未结 6 991
盖世英雄少女心
盖世英雄少女心 2020-12-03 02:40

I am working with Django for a first time and I\'m trying to build an API and I am following some tutorials and examples and it works right, but I am running the project now

6条回答
  •  攒了一身酷
    2020-12-03 03:41

    In my case, what I did was I inherited my view from viewsets.Viewset which is in rest_framework module and additionally, I added the basename = your_name argument in the router.register() function during registration.

    The view would look something like:

    class SessionViewSet(viewsets.ViewSet):
        queryset = Session.objects.all()
        serializer_class = SessionSerializer
    
        def get(self, request, format=None):
            return Response("test")
    

    The router registeration would look something like:

    router.register(r'your_app_name', YourModelNameView, basename='your_app_name')
    

提交回复
热议问题