0
這是我的第一個django應用程序,我想知道是否有可能擴展所有視圖的普通類。例如Django:在基於類的視圖中添加另一個子類
class GeneralParent:
def __init__(self):
#SETTING Up different variables
self.LoggedIn = false
def isLoggedIn(self):
return self.LoggedIn
class FirstView(TemplateView):
####other stuff##
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
allLeads = len(self.getAllLeads())
context['isLoggedIn'] = ####CALL GENEREAL PARENT CLASS METHOD###
return context
class SecondView(FormView):
####other stuff##
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
allLeads = len(self.getAllLeads())
context['isLoggedIn'] = ####CALL GENEREAL PARENT CLASS METHOD###
return context
這在django中可能嗎?
它的工作,但爲什麼我的類需要繼承對象? –
'超'只適用於新型的類(從'object'繼承) - 更多信息 - https://docs.python.org/2/glossary.html#term-new-style-class –