Django viewset has not attribute 'get_extra_actions'

前端 未结 6 993
盖世英雄少女心
盖世英雄少女心 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:43

    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.

提交回复
热议问题