close

[Solved] Django viewset has not attribute ‘get_extra_actions’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Django viewset has not attribute ‘get_extra_actions’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Django viewset has not attribute ‘get_extra_actions’ Error Occurs?

Today I get the following error Django viewset has not attribute ‘get_extra_actions’ in python.

How To Solve Django viewset has not attribute ‘get_extra_actions’ Error ?

  1. How To Solve Django viewset has not attribute 'get_extra_actions' Error ?

    To Solve Django viewset has not attribute 'get_extra_actions' Error 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.

  2. Django viewset has not attribute 'get_extra_actions'

    To Solve Django viewset has not attribute 'get_extra_actions' Error 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.

Solution 1

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.

Solution 2

Before Django Rest Framework v3.8 you could register an APIView directly with a router. I did this extensively to gain a nice collated (and versioned) auto-documenting API for some very custom API endpoints. Given the choice again, I would probably write the whole thing a more standard way, but that isn’t an option for everybody.

But after digging into the error, it turns out you can just patch over the problem by giving the router what it wants and adding a dummy get_extra_actions classmethod.

class MyAPIView(APIView):

    @classmethod
    def get_extra_actions(cls):
        return []

#...

I’m not saying this is good, but it works for now.
I’ve got my documentation back and I’ve managed to upgrade to DRFv3.8.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read