class ContextMixin(object): def get_context_data(self, **kwargs): print('contextmixin') class FormMixin(ContextMixin): def get_context_data(self, **kwargs): print('formmixin') super(FormMixin, self).get_context_data(**kwargs) class SingleObjectMixin(ContextMixin): def get_context_data(self, **kwargs): print('singleobjectmixin') super(SingleObjectMixin, self).get_context_data(**kwargs) class ModelFormMixin(FormMixin, SingleObjectMixin): pass class View(): pass class ProcessFormView(View): def get(self): self.get_context_data() class BaseUpdateView(ModelFormMixin, ProcessFormView): pass bv = BaseUpdateView().get() mro = BaseUpdateView.__mro__ for m in mro: print(m)
输出结果:
formmixin singleobjectmixin contextmixin <class '__main__.BaseUpdateView'> <class '__main__.ModelFormMixin'> <class '__main__.FormMixin'> <class '__main__.SingleObjectMixin'> <class '__main__.ContextMixin'> <class '__main__.ProcessFormView'> <class '__main__.View'> <class 'object'>