Prometheus
Prometheus

Reputation: 33625

Python Super not working in example shown why?

What I'm I doing wrong below? In ClassA I have access to request.DATA I pass this into the Base class but get the error:

AttributeError: 'Base' object has no attribute 'DATA'

But this should have access as I pass in request, so why is this not working?

class Base(object):
    def post(self, request, *args, **kwargs):
        print("=========After==============")
        print(request.DATA)



class ClassA(Base):
    def post(self, request, *args, **kwargs):

        print("=========Before=============")
        print(request.DATA)

        super(ClassA, self).post(self, request, *args, **kwargs)

Upvotes: 0

Views: 61

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599620

You're passing self twice in the super call. The call to post is a standard method call, so self is always included automatically. It should be:

 super(ClassA, self).post(request, *args, **kwargs)

Upvotes: 2

Related Questions