def post(self, *args, **kwargs): ret = {'status': False, 'summary': '', 'detail': {}} try: form = JdProductPriceForm() is_valid = form.valid(self) if is_valid: form._value_dict.pop('nid') merchant_id = 14 service = ProductService(ProductRepository()) service.create_price(merchant_id, form._value_dict['product_id'], form._value_dict) else: ret['detail'] = form._error_dict raise Exception('输入内容不合法') ret['status'] = True except Exception as e: ret['summary'] = str(e) self.write(json.dumps(ret))
def post(self, *args, **kwargs): print("self:", self) ret = {"status": False, "summary": "", "detail": {}} try: form = JdProductPriceForm() #创建form表单 is_valid = form.valid(self) #实例化form表单 if is_valid: form._value_dict.pop("nid") merchant_id = 6 service = ProductService(ProductRepository()) service.create_price(merchant_id, form._value_dict["product_id"], form._value_dict) else: ret["detail"] = form._error_dict raise Exception("输入内容不合法") ret["status"] = True except Exception as e: ret["summary"] = str(e) self.write(json.dumps(ret))