• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

94.(后端)分类参数ID获取接口实现——restful发送请求查询数据

武飞扬头像
想成为数据分析师的开发工程师
帮助1

1.概述

这里通过id参数,使用get请求查询数据

2.代码展示

# attribute表
# restful形式发送请求
class Attribute(Resource):
    # 增加数据
    def post(self):
        name = request.form.get('name')
        cid = request.form.get('cid')
        _type = request.form.get('_type')
        val = request.form.get('val')

        if all([name, cid, _type]):
            if val:
                attr = models.Attribute(name=name, cid=int(cid), _type=_type, val=val)
            else:
                attr = models.Attribute(name=name, cid=int(cid), _type=_type)
            db.session.add(attr)
            db.session.commit()
            return to_dict_msg(200,msg="添加商品分类数据成功!!!!")
        else:
            return to_dict_msg(10000)

    # 查询数据
    def get(self):
        try:
            id = request.args.get('id')
            attr = models.Attribute.query.get(id)
            if attr:
                return to_dict_msg(200, attr.to_dict(), msg="获取分类参数成功!!!")
            else:
                return to_dict_msg(10022)
        except Exception as e:
            return to_dict_msg(20000)
attribute_api.add_resource(Attribute, '/attribute')

3.Postman测试接口

学新通
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhhafiga
系列文章
更多 icon
同类精品
更多 icon
继续加载