Как вызвать словарь суперкласса и обновить его - Python - PullRequest
1 голос
/ 25 апреля 2019

Как вызвать родительский класс в 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)

1 Ответ

0 голосов
/ 25 апреля 2019

В Python 3 вы можете вызвать метод класса родителя следующим образом:

    def get_context(self, request)
       context = super().get_context(request)
       context.update({'mode': self.mode})
       return context
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...