Python class 继承 - 如何从以前的继承中继承?

Python class inheritance - how to have inheritance from a previous inheritance?

我有一个class这样的。

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

我还有一个这样的class。

 class SecondClass(FirstClass):

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

我原以为第二个Class 会继承MethodView Class。但它并没有继承它。当有 POST 调用时,MethodView 将调用“post”def,但它不执行“post”函数。我应该怎么做才能让 SecondClass 继承 MethodView class?

我希望避免(由于代码复杂)

 class SecondClass(FirstClass, MethodView):

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

当我执行上述操作时,当有 POST 调用时,MethodView 会启动以执行“post”函数。

应该可以。 SecondClass 是 MethodView 的间接子类。 SecondClass 拥有 MethodView 拥有的所有 public 方法和成员,因为所有这些东西都是通过 FirstClass 继承的。

SecondClass 的 post 方法正在覆盖 MethodView 的 post 方法。

要在 SecondClass 的 post 方法中评估 MethodView 的 post 方法,请使用 super() 函数

class SecondClass(FirstClass, MethodView):

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

More here on the super function