78-多接口用例18/返回值提取(路径/正则)+UI优化

参考大佬文章:78
路径法只能是识别提取json格式,有些接口返回值并不是json格式字串
暂时规定正则提取出来的全部按照字符串处理

真实接口测试

在这里插入图片描述

提取–路径法

在这里插入图片描述

在这里插入图片描述

提取–正则法

在这里插入图片描述
在这里插入图片描述

完整

在这里插入图片描述

UI优化

P_apis.html:
部分:

<tr>
        <th>id</th>
        <th style="width: 30%">接口名称</th>
        <th style="width: 30%">url</th>
        <th style="width: 350px">操作</th>
    </tr>
    </thead>
    {#具体内容#}
    <tbody>
    {% for i in apis %}
        <tr>
            <td>{{ i.id }}</td>
            <td>{{ i.name }}</td>
            <td>{{ i.short_url }}</td>

views.py
部分

def child_json(eid, oid='', ooid=''):
    res = {}
    if eid == 'home.html':
        date = DB_home_href.objects.all()
        home_log = DB_apis_log.objects.filter(user_id=oid)[::-1]
        if ooid == '':
            res = {"hrefs": date, "home_log": home_log}
        else:
            log = DB_apis_log.objects.filter(id=ooid)[0]
            res = {"hrefs": date, "home_log": home_log, "log": log}

    if eid == 'project_list.html':
        date = DB_project.objects.all()
        res = {"projects": date}

    if eid == 'P_apis.html':
        project = DB_project.objects.filter(id=oid)[0]
        apis = DB_apis.objects.filter(project_id=oid)
        for i in apis:
            try:
                i.short_url = i.api_url.split('?')[0][:50]
            except:
                i.short_url = ''
        res = {"project": project, 'apis': apis}
# 新增接口
def project_api_add(request, Pid):
    project_id = Pid
    DB_apis.objects.create(project_id=project_id, name='', api_url='', api_method='none', api_header='')

    # 强制重定向到项目接口库,href类会导致页面刷新的后端函数可重定向到初始路由,防止出现问题
    return HttpResponseRedirect('/apis/%s/' % project_id)

【更新】
问题:前端页面一直无法获取到short_url的数据
原因:粗心大意。。。在child_json函数里出现了两个P_apis.html页面的判断。。
在这里插入图片描述
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值