模板继承的实践

模板基础实现用户编辑:

一.实现基本的功能页面逻辑

path('user/list/', views.user_list),
def user_list(request):
    """"用户管理"""
    return render(request, 'user_list.html')

layout.html 模板,不要忘记加入bootstrap和jQuery的包。 

 使用模板,在需要创建的页面中加入合适的表单。

 用户列表

def user_list(request):
    """"用户管理"""

    # 获取所有的用户列表
    queryset = models.UserInfo.objects.all()
    # for obj in queryset:
    #     print(obj.id, obj.name)
    return render(request, 'user_list.html', {"queryset": queryset})
{% extends 'layout.html' %}


{% block content %}
<div class="container">
    <div style="margin-bottom: 10px">
        <a class="btn btn-primary" href="#">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
            新建用户
        </a>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <span class="glyphicon glyphicon-th" aria-hidden="true"></span>
            用户列表
        </div>
        <div class="panel-body">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>密码</th>
                    <th>年龄</th>
                    <th>余额</th>
                    <th>入职时间</th>
                    <th>性别</th>
                    <th>所属部门</th>
                    <th>操作</th>

                </tr>
                </thead>
                <tbody>
                {% for obj in queryset %}
                <tr>
                    <th>{{obj.id}}</th>
                    <td>{{obj.name}}</td>
                    <td>{{obj.password}}</td>
                    <td>{{obj.age}}</td>
                    <td>{{obj.account}}</td>
                    <td>{{obj.create_time|date:"Y-m-d H:i:s"}}</td>
                    <td>{{obj.get_gender_display}}</td>
                    <td>{{obj.depart.title}}</td>

                    <td>
                        <a class="btn btn-primary btn-xs" href="#">编辑</a>
                        <a class="btn btn-danger btn-xs" href="#">删除</a>
                    </td>
                </tr>
                {% endfor %}

                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值