赞
踩
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)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。