from rest_framework.views import APIView
from rest_framework import exceptions
class MyAuthentication(object):
def authenticate(self, request):
token = request._request.GET.get('token')
if not token:
raise exceptions.AuthenticationFailed('用户认证失败')
return ("alex", None)
def authenticate_header(self, val):
pass
class DogView(APIView):
################### 重点########################
authentication_classes = [MyAuthentication] # 用户认证
authentication_classes = [] # 不做用户认证
permission_classes = [] # 不做权限认证
################### 重点########################
def get(self, request, *args, **kwargs):
ret = {
'code': 10000,
'msg': 'GET获取成功'
}
return HttpResponse(json.dumps(ret), status=201)
django_rest_framework——用户认证
猜你喜欢
转载自blog.csdn.net/weixin_44053341/article/details/109710717
今日推荐
周排行