1.在utils/新建一个文件minx_utils.py文件里面
# coding=utf-8 from django.contrib.auth.decorators import login_required from django.utils.decorators import method_decorator class LoginRequiredMixin(object): @method_decorator(login_required(login_url='/login/')) def dispatch(self,request,*args,**kwargs): return super(LoginRequiredMixin,self).dispatch(request,*args,**kwargs) 2.在views文件里面
from utils.mixin_utils import LoginRequiredMixin 将类改为:
class CourseInfoView(LoginRequiredMixin,View)