2020-11-10

drf——drf认证功能源码分析

一、drf认证功能源码分析

1 APIView---》dispatch---》self.initial(request, *args, **kwargs)--》self.perform_authentication(request)
---》Request.user--->self._authenticate(self):Request类的方法---》self.authenticators:Request类的属性---》在Request对象实例化的时候传入的
----》Request在什么时候实例化的?dispatch的时候
---》APIView:self.get_authenticators()--》return [auth() for auth in self.authentication_classes]
----》如果在自己定义的视图类中写了authentication_classes=[类1,类2]----》Request的self.authenticators就变成了我们配置的一个个类的对象 2 self._authenticate(self):Request类的方法def _authenticate(self): for authenticator in self.authenticators: # BookView中配置的一个个类的对象 try: user_auth_tuple = authenticator.authenticate(self) except exceptions.APIException: self._not_authenticated() raise if user_auth_tuple is not None: self._authenticator = authenticator self.user, self.auth = user_auth_tuple return3 只要在视图类中配置authentication_classes = [MyAuthen.LoginAuth, ] 就会执行上面的方法,执行认证

 

原文转载:http://www.shaoqun.com/a/489724.html

crowd:https://www.ikjzd.com/w/880

olive:https://www.ikjzd.com/w/2025

首信易:https://www.ikjzd.com/w/1841


一、drf认证功能源码分析1APIView---》dispatch---》self.initial(request,*args,**kwargs)--》self.perform_authentication(request)---》Request.user--->self._authenticate(self):Request类的方法---》self.authenticators:Reque
淘粉8:https://www.ikjzd.com/w/1725
扬帆计划:https://www.ikjzd.com/w/1581
美国站如何注册?2018年亚马逊美国站注册新变化及流程揭秘!:https://www.ikjzd.com/home/1660
北京5日游路线规划:http://tour.shaoqun.com/a/28008.html
现在入驻shopee还来得及吗?如何运营好shopee新账号?:https://www.ikjzd.com/home/110994

No comments:

Post a Comment