from django.views import View from django.utils.decorators import method_decorator # 使用登录认证装饰器 # 用法一 # @method_decorator(login_auth,name='get') # @method_decorator(login_auth,name='post') class UserInfo(View): # 用法二 @method_decorator(login_auth) def get(self, request, *args, **kwargs): return HttpResponse('userinfo get') # 总结:两种用法 -加在类上:@method_decorator(login_auth,name='get') -加载方法上:@method_decorator(login_auth)