0

I have a class like this.

 from flask.views import MethodView
 class FirstClass(MethodView):

I have another class like this.

 class SecondClass(FirstClass):

     def post(self):
         logging.info(self.request.body)

I was expecting that the SecondClass would inherit MethodView Class. But it is not inheriting it. The MethodView will call the "post" def when there is a POST call, but it is not executing the "post" function. What should I do to have the SecondClass inherit MethodView class?

I was hoping to avoid (due to complexity in code)

 class SecondClass(FirstClass, MethodView):

     def post(self):
         logging.info(self.request.body)

When I do the above the MethodView kicks in to execute the "post" function when there is a POST call.

2
  • Could you clarify what you mean by "it is not inheriting it"? issubclass(SecondClass, MethodView) == True, no? Commented May 31, 2021 at 0:01
  • Just clarified my problem. Commented May 31, 2021 at 0:04

2 Answers 2

1

It should work. SecondClass is indirect son of MethodView. SecondClass has all public method and members that MethodView has, because all these things are inherited through FirstClass.

Sign up to request clarification or add additional context in comments.

Comments

1

SecondClass's post method is overriding the post method of MethodView.

To assess MethodView's post method inside SecondClass's post method use the super() function

class SecondClass(FirstClass, MethodView):

     def post(self):
         logging.info(self.request.body)
         super(SecondClass, self).post()

More here on the super function

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.