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

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

结果如下:

相关推荐
青铜发条8 分钟前
【python】python进阶——logging日志模块
python
superlls26 分钟前
(计算机网络)JWT三部分及 Signature 作用
java·开发语言·计算机网络
无规则ai39 分钟前
动手学深度学习(pytorch版):第六章节—卷积神经网络(1)从全连接层到卷积
人工智能·pytorch·python·深度学习·cnn
一只鲲1 小时前
56 C++ 现代C++编程艺术5-万能引用
开发语言·c++
秋难降1 小时前
优雅的代码是什么样的?🫣
java·python·代码规范
liulilittle2 小时前
.NET反射与IL反编译核心技术
开发语言·数据库·c#·.net·反射·反编译·il
二闹2 小时前
聊天怕被老板发现?摩斯密码来帮你
后端·python
扛麻袋的少年2 小时前
6.Kotlin的Duration类
android·开发语言·kotlin
mit6.8242 小时前
[RestGPT] OpenAPI规范(OAS)
人工智能·python
360安全应急响应中心2 小时前
Python代码保护之重置操作码映射的攻与防探究(一)
python·逆向