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

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

结果如下:

相关推荐
用户83562907805113 小时前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
侃侃_天下13 小时前
最终的信号类
开发语言·c++·算法
c8i13 小时前
python中类的基本结构、特殊属性于MRO理解
python
echoarts14 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
liwulin050614 小时前
【ESP32-CAM】HELLO WORLD
python
Aomnitrix14 小时前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
Doris_202314 小时前
Python条件判断语句 if、elif 、else
前端·后端·python
Doris_202314 小时前
Python 模式匹配match case
前端·后端·python
每天回答3个问题15 小时前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说15 小时前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox