2020-11-17 发表在 编程语言 15
代码语言:javascript复制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
代码语言:javascript复制## 使用
代码语言:javascript复制 @requires('out_trade_no', 'total_amount', 'subject', 'platform')
def create(request):
pass