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 –