我有两个从模板视图继承的视图,需要通过 required_login 登录。当我单独创建视图时很简单:
class AboutView(TemplateView):
template_name = 'app1/about.html'
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(AboutView, self).dispatch(*args, **kwargs)
class HelpView(TemplateView):
template_name = 'app1/help.html'
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(HelpView, self).dispatch(*args, **kwargs)
这确实有效。问题是为什么下面的代码不起作用
class StaticTemplateView(TemplateView):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(AboutView, self).dispatch(*args, **kwargs)
class AboutView(StaticTemplateView):
template_name = 'app1/about.html'
class HelpView(StaticTemplateView):
template_name = 'app1/help.html'
这里的错误:
super(type, obj): obj must be an instance or subtype of type
提前致谢