django自定义CBV装饰器
from django.utils.decorators import method_decorator
def my_decorators(func):
def wrapper(request,*args,**kwargs):
uid = request.GET.get('uid')
print(uid)
res_jwt = request.GET.get('jwt')
print(res_jwt)
my_jwt = jwt_decode(res_jwt,payload).get('uid')
print(my_jwt)
if res_jwt == None:
return HttpResponse('你没带上令牌')
if str(uid) != str(my_jwt):
return HttpResponse('你篡改了用户id')
return func(request,*args,**kwargs)
return wrapper
class DetailsGoods(APIView):
@method_decorator(myside)
def get(self,request):
gid = request.GET.get('gid','null')
goods = Goods.objects.get(id=gid)
goods_ser = GoodsSer(goods).data
res = {}
res['data'] = goods_ser
return Response(res)