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),

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

结果如下:

相关推荐
怕浪猫1 小时前
RAG 面试 6 连问,从原理到优化全部覆盖
python·算法·面试
高洁011 小时前
具身智能中的世界模型训练
人工智能·python·深度学习·机器学习·transformer
无线通信科研笔记1 小时前
IEEE TVT 2026 论文精读与完整复现|相位误差如何重塑近场 RIS 的幅相响应
论文阅读·人工智能·python·算法·论文笔记
朝朝辞暮i2 小时前
VLA 系统学习第 1 课:VLA 到底在干什么?
人工智能·python·计算机视觉·vla
2601_962885722 小时前
如何用 Python 自动识别股票的支撑位与压力位?
开发语言·python
爱吃奥利奥_wen3 小时前
面向对象三板斧:封装、继承、多态,到底在“装“什么、“承“什么、“变“什么?
开发语言·经验分享·c#
北冥有鱼被烹3 小时前
VCSEL全景解析:与光模块NPO CPO的关系、市场量化分析与产业链影响
python
我可能是个假开发3 小时前
FTP Unicode 文件名导致 `550` 的问题分析与解决方案
java·开发语言·spring
caoerzhong3 小时前
中小企业上 WMS 该先上哪几块:JeeWMS 开源 Java 仓库管理系统的分批上线清单
java·python·开源
正在走向自律3 小时前
AI数据分析与可视化:从基础到应用实践
服务器·人工智能·python·机器学习·数据分析·pandas