
这里主要是处理接受的数据异常
返回异常
用到的异常:参数异常ValueError
from django.http import JsonResponsedef i_xxx(request):try:req = json.loads(request.body)data = req.get("data", None)if data is None:raise ValueError("缺少data参数!")id = data.get("id", None)if id is None:raise ValueError("缺少id参数!")flag = xxx(id, data)return_data = {"code": "10001", "result": flag, "errMsg": "ok"}return JsonResponse(return_data)except Exception as e:return_data = {"code": "10002", "result": "", "errMsg": str(e)}return JsonResponse(return_data)