zoukankan      html  css  js  c++  java
  • 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 return 3 只要在视图类中配置authentication_classes = [MyAuthen.LoginAuth, ] 就会执行上面的方法,执行认证
  • 相关阅读:
    2020/5/8
    2020/5/8
    2020/5/6
    2020/4/30
    2020/4/29
    2020/4/28
    2020/4/27
    KMP算法详解
    博客搬家声明
    洛谷P2831 NOIP2016 愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/guojieying/p/13956126.html
Copyright © 2011-2022 走看看