美文网首页
RESTFUL认证流程

RESTFUL认证流程

作者: Forever_f59e | 来源:发表于2019-07-10 09:27 被阅读0次

方法一:

    class Myauthentication(object):
        def authenticate(self, request):
             token = request._request.GET.get('token')
             if token and token == '123':
                 return ('lisi', token)
            else:
                raise AuthenticationFailed('认证失败')

        def authenticate_header(self, request):#不写这个方法会报这个方法错
            pass

方法二:

    from rest_framework.authentication import BaseAuthentication
    class Myauthentication(BaseAuthentication):
        def authenticate(self, request):
              token = request._request.GET.get('token')
              if token and token == '123':
                  return ('lisi', token)
            else:
                  raise AuthenticationFailed('认证失败')

!!两种方法写完后 需要调用认证方法类

    authentication_classes = [Myauthentication,]#调用认证类方法
    #调用方式

相关文章

网友评论

      本文标题:RESTFUL认证流程

      本文链接:https://www.haomeiwen.com/subject/alcckctx.html