我尝试在我的Django应用程序中的几个基于类的视图的分派方法上使用decorator。下面是我尝试的一个示例视图:
class DashboardView(TemplateView):
template_name="omninectar/dashboard.html"
def get_context_data(self, **kwargs):
....
@active_and_login_required
def dispatch(self, *args, **kwargs):
return super(DashboardView, self).dispatch(*args, **kwargs)
有以下装饰:
^{pr2}$我得到了以下错误:
AttributeError at /dashboard/
'DashboardView' object has no attribute 'user'
如何让decorator使用此视图检索当前用户?在
您可以使用
django.utils.decorators.method_decorator
将旧样式的修饰符转换为方法修饰符:相关文档在这里:Introduction to Class-based Views
相关问题 更多 >
编程相关推荐