Python(django)之单一接口展示功能前端开发

1、代码

建立apis_manage.html

代码如下:

复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>测试平台</title>
</head>
<body role="document">
<nav class = "navbar navbar-inverse navbar-fixed-top">
    <div class = "container">
    <div class="navbar-header">
        <a class = "navbar-brand" href="#">测试平台</a>
    </div>
        <div id="navbar" class = "collapse navbar-collapse">
            <ul class = "nav navbar-nav">
                <li class = "active"><a href="#">测试平台</a></li>
                <li ><a href="#">流程接口测试</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">{{ user }}</a></li>
                <li><a href="/logout/">退出</a></li>
            </ul>
        </div>
    </div>
</nav>
<div class="row" style="padding-top: 20px">
    <div class="col-md-11">
        <table class="table table-striped">
            <thead>
            <tr>
                <th>所属产品</th>
                <th>所属用例</th>
                <th>步骤</th>
                <th>URL地址</th>
                <th>参数=值</th>
                <th>方法</th>
                <th>预期结果</th>
                <th>测试结果</th>
                <th>执行时间</th>
            </tr>
            </thead>
            <tbody>
            {%  for apistep in apisteps %}
            <tr>
                <td>{{ apistep.Apitest.Product.product_name }}</td>
                <td>case{{ apistep.Apitest.id }}:{{ apistep.Apitest.apitestname }}</td>
                <td>{{ apistep.apiurl }}</td>
                <td>{{ apistep.apiparamvalue }}</td>
                <td>{{ apistep.apimethod }}</td>
                <td>{{ apistep.apiresult }}</td>
                <td>{% if apistep.apistatus == 1   %}
                <a style="color:green">{{ apistep.apistatus }}</a>
                {% else %}
                    <a style="color:red">{{ apistep.apistatus }}</a>
                {% endif %}
                </td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
</div>

</body>
</html>

2、创建视图

在views.py加入以下代码

复制代码
@login_required()
def apis_manage(request):
    username = request.session.get('user', '')
    apis_list = Apis.objects.all()
    return render(request, "apis_manage.html", {"user": username, "apiss": apis_list})

3、加入路径

在urls.py加入以下代码

复制代码
path('apis_manage/', views.apis_manage),

后进行数据库更新跟前面一样

结果如下:

相关推荐
Blossom.1181 天前
基于多模态大模型的工业质检系统:从AOI到“零样本“缺陷识别的产线实践
运维·人工智能·python·机器学习·自动化·测试用例·知识图谱
程序员-King.1 天前
【Qt开源项目】— ModbusScope-day 4
开发语言·qt
j_hy1 天前
OOP组件及事件处理(一)
java·开发语言
南棱笑笑生1 天前
20251215给飞凌OK3588-C开发板适配Rockchip原厂的Buildroot【linux-5.10】后调通typeC1接口
linux·c语言·开发语言·rockchip
雍凉明月夜1 天前
视觉opencv学习笔记Ⅴ-数据增强(1)
人工智能·python·opencv·计算机视觉
金牌归来发现妻女流落街头1 天前
【阻塞队列的等待唤醒机制】
java·开发语言·阻塞队列
骚戴1 天前
深入解析:Gemini 3.0 Pro 的 SSE 流式响应与跨区域延迟优化实践
java·人工智能·python·大模型·llm
毕设源码-朱学姐1 天前
【开题答辩全过程】以 基于Java技术的羽毛球积分赛管理系统的设计与实现 为例,包含答辩的问题和答案
java·开发语言
2501_941982051 天前
Go 进阶:发送文件/图片消息的流程与实现
开发语言·后端·golang
smj2302_796826521 天前
解决leetcode第3777题使子字符串变交替的最少删除次数
python·算法·leetcode