当前位置:   article > 正文

django_rest_framework——用户认证_django rest framework 用户认证

django rest framework 用户认证
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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/876774
推荐阅读
相关标签
  

闽ICP备14008679号