1

我有两个从模板视图继承的视图,需要通过 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

提前致谢

4

1 回答 1

2

我认为错误在于复制/粘贴:)

反而:

return super(AboutView, self).dispatch(*args, **kwargs)

尝试这个:

return super(StaticTemplateView, self).dispatch(*args, **kwargs)
于 2013-07-03T12:35:15.423 回答