Django2.0之Rest Framework 认证流程再梳理


  1. 客户端请求发出后首先走dispatch方法:

views.py:
def dispatch(self, request, *args, **kwargs):
    #首先初始化原始request
    request = self.initialize_request(request, *args, **kwargs)
    #在调用请求方法之前要处理的事情
    self.initial(request, *args, **kwargs)
    #将最终的response返回
     self.response = self.finalize_response(request, response, *args, **kwargs)             

1.1. initialize_request方法

# 返回一个封装好的request对象包含原始的request,还有一个校验器
def initialize_request(self, request, *args, **kwargs):
    """
    Returns the initial request object.
    """
    return Request(
        request,
        authenticators=self.get_authenticators(),
    )

1.2. initial方法

def initial(self, request, *args, **kwargs):
    """
    Runs anything that needs to occur prior to calling the method handler.
    """

    # 确保进来的请求是被允许的
    self.perform_authentication(request)
    self.check_permissions(request)
    self.check_throttles(request)

1.3.finalize_response方法,不深究了!

未完~~~

你可能感兴趣的:(django)