在网址中声明时,需要在基于类的视图的末尾使用as_view():
path('', views.HomeView.as_view(), name='homepage'),另外,使用
login_required装饰器时,需要在CBV的分派方法上使用它:
from django.contrib.auth.decorators import login_requiredfrom django.utils.decorators import method_decoratorclass HomeView(ListView): @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(HomeView, self).dispatch(*args, **kwargs)



