参考大佬文章: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页面的判断。。