mixin_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)
写view的时候,直接继承LoginRequiredMixin,如果未登录,则跳转到登陆页面