完成用户列表的基本功能

main
roger_home_pc 1 year ago
parent 46414d2835
commit 30e8873ca6
  1. 2
      apps/user/urls.py
  2. 49
      apps/user/views.py
  3. 6
      templates/user/index.html

@ -22,4 +22,6 @@ urlpatterns = [
path('user_reg/', views.user_reg),
path('user_login/', views.user_login),
path('ajax_login_data/', views.ajax_login_data),
path('index/', views.index),
path('del/', views.delete),
]

@ -1,6 +1,7 @@
from django.shortcuts import render
from django.contrib.auth import authenticate, login
from django.http.response import JsonResponse
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from .forms import UserRegForm
from apps.user.models import MyUser
@ -69,3 +70,51 @@ def ajax_login_data(request):
json_dict['code'] = '1004'
json_dict['msg'] = '用户名密码为空'
return JsonResponse(json_dict)
def index(request):
if request.method == "GET":
level = request.GET.get("level")
truename = request.GET.get("truename", "")
status = request.GET.get("status")
search_dict = dict()
if level:
search_dict["level"] = level
if truename:
search_dict["truename"] = truename
if status:
search_dict["status"] = status
datas = MyUser.objects.filter(**search_dict).order_by("-id")
page_size = 5 # 每页显示的行数
try:
if not request.GET.get("page"):
current_page = 1
current_page = int(request.GET.get("page"))
except:
current_page = 1
paginator = Paginator(datas, page_size)
try:
users = paginator.page(current_page)
except PageNotAnInteger:
users = paginator.page(1)
except EmptyPage:
users = paginator.page(1)
context = {
'level': level,
'truename': truename,
'status': status,
'users': users
}
print(context)
return render(request, 'user/index.html', context=context)
def delete(request, _id):
obj = MyUser.objects.filter(id=_id)
obj.delete()
json_dict = dict(code=200, msg='删除数据成功')
return JsonResponse(json_dict)

@ -102,7 +102,7 @@
<a class="btn btn-primary single" href="#">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger" href="javascript:void(0)" onclick="showDeleteModel(this)">删除</a>
<a class="btn btn-danger" href="javascript:void(0)" onclick="showDeleteModal(this)">删除</a>
<input type="hidden" id="id_hidden" value="{{ u.id }}">
</td>
</tr>
@ -151,7 +151,7 @@
</nav>
</div>
{# 删除信息 #}
<div class="modal fade" id="delModel" tabindex="-1" aria-hidden="true">
<div class="modal fade" id="delModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
@ -184,7 +184,7 @@
backdrop: 'static',
keyboard: false
});
}
};
$(function () {
$("#delButton").click(function (){

Loading…
Cancel
Save