方法一:
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,]#调用认证类方法
#调用方式