模板基础实现用户编辑:
一.实现基本的功能页面逻辑
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 %}