def requires(*params):
def _deco(view_func):
@wraps(view_func)
def _handler(request, *args, **kw):
# 校验参数
for key in params:
if key not in request.GET:
return JsonResponse(data={
'code': 'CHECK_ERROR',
'msg': '参数校验出错,"{}"是必选的!'.format(key)
})
response = view_func(request, *args, **kw)
return response
return _handler
return _deco
def requires(*params):
def _deco(view_func):
@wraps(view_func)
def _handler(request, *args, **kw):
# 校验参数
for key in params:
if key not in request.GET:
return JsonResponse(data={
'code': 'CHECK_ERROR',
'msg': '参数校验出错,"{}"是必选的!'.format(key)
})
response = view_func(request, *args, **kw)
return response
return _handler
return _deco
@requires('out_trade_no', 'total_amount', 'subject', 'platform')
def create(request):
pass
@requires('out_trade_no', 'total_amount', 'subject', 'platform')
def create(request):
pass