如何在Python中调用父类并加入两个字典
提前谢谢了。
class Base(View):
title = 'abc'
slug = 'abc-12'
def get_context(self, request):
return {'title': self.title, 'slug': self.slug }
class Logbook(Base)
mode = 'read'
def get_context(self, request)
# call super class
return super().add('mode': self.mode)
# i want {'title': 'abc', 'slug': 'abc-12', mode: 'read' }
def get(self, request)
context = self.get_context(request)
在python 3中,您可以通过以下方式调用父类的方法:
def get_context(self, request)
context = super().get_context(request)
context.update({'mode': self.mode})
return context