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

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

结果如下:

相关推荐
我不是懒洋洋5 分钟前
【C++】内存管理与模板(C++内存管理方式、new和delete的实现原理、malloc/free和new/delete的区别、函数模板、类模板)
c语言·开发语言·c++·青少年编程·visual studio
雪的季节6 分钟前
Qt多窗口架构设计需求简介
开发语言·qt
z2005093010 分钟前
【linux学习】深入理解 Linux 下的静态库与动态库
开发语言·c++·算法
2601_9611940211 分钟前
考研政治历年真题库
python·考研·django·virtualenv·pygame·tornado
韦胖漫谈IT12 分钟前
面向对象 vs 函数式背后的思维差异
开发语言
兰令水12 分钟前
【helloagent】第四章 agent范式总结+面经
python·语言模型
Xin_ye1008615 分钟前
C# 零基础到精通教程 - WPF 深度专题:3D 图形与视觉增强
开发语言·c#·wpf
AI视觉网奇17 分钟前
3d查看 预览软件
python
zhangfeng11331 小时前
台大李宏毅老师讲解memba和类似linear atttenion 模型,笔记
开发语言·人工智能·笔记
Chris _data2 小时前
并发单词频率统计器 - 从零到完整实现(C# 实战)
开发语言·c#