装饰器写法
# 游客小游戏 看视频 def device_youke_mingame(name=None): def youke_mingame(view): @functools.wraps(view) def _wrapped(*args, **kwargs): try: r_json = request.get_json() device_id = r_json.get("device_id", None) device_details = DeviceDetails.get_by_id(device_id) if device_details: if name == "addition": # 30%分数加成 key = "yk|addition_3||{}".format(device_details.id) rds_extra.set(key, 0.3) rds_extra.expire(key, 3600 * 24) device_details.total_video_count = getattr(device_details, "total_video_count", 0) + 1 device_details.save() return JsonResponse.response(code=1, user_id=device_details.id) return view(*args, **kwargs) except Exception as e: logger.exception(e) return _wrapped return youke_mingame