项目运行
需要先安装Python的相关依赖:pymysql,Django==3.2.8,pillow 使用pip install 安装
第一步:创建数据库
第二步:执行SQL语句,.sql文件,运行该文件中的SQL语句
第三步:修改源代码中的settings.py文件,改成自己的mysql数据库用户名和密码
第四步:运行命令:python manage.py runserver 8000
第五步:打开浏览器查看http://127.0.0.1:8000
毕设帮助,指导,本源码分享(见文末)
系统介绍:
本系统是一款基于Django框架和Python语言开发的酒店客房入侵检测系统,旨在通过人脸识别技术提升酒店的安全管理水平。系统通过采集客户的面部信息,实现对客房的安全管理,防止未授权人员的入侵,同时提供客房管理和客户管理等功能。
整体功能包含:
客房管理数据统计
客户管理数据页面
客户信息录入界面
人脸识别功能
客房入侵检测
前台模块:
客户入住信息录入
客房状态查看
客户面部信息采集
后台模块:
客房管理:查看客房状态,管理客房信息
客户管理:管理客户信息,包括面部信息
系统设置:配置系统参数,如数据库连接等
入侵检测:实时监控客房状态,检测非法入侵
功能截图:
代码实现:
def register(request):"""注册账号:return:"""try:name = request.POST.get('username')passwd = request.POST.get('password')phone = request.POST.get('phone')user = User.objects.filter(name=name)if user:return JsonResponse({'message': '用户已存在,请直接登录'}, status=403)User.objects.create(name=name,password=passwd,phone=phone,role=2,description='')response_data = {'message': '注册成功'}return JsonResponse(response_data)except Exception as e:print(e)return JsonResponse({'message': '注册失败'}, status=401)def password(request):username = request.session['username']role = int(request.session['role'])user_id = request.session['user_id']return render(request, 'modify_password.html', locals())def get_user(request):"""获取用户列表信息 | 模糊查询:param request::return:"""keyword = request.GET.get('name')page = request.GET.get("page", '')limit = request.GET.get("limit", '')role_id = request.GET.get('position', '')response_data = {}response_data['code'] = 0response_data['msg'] = ''data = []if keyword is None:results_obj = User.objects.all()else:results_obj = User.objects.filter(name__contains=keyword).all()paginator = Paginator(results_obj, limit)results = paginator.page(page)if results:for user in results:record = {"id": user.id,"name": user.name,"password": user.password,"phone": user.phone,"role": user.role,'create_time': user.create_time.strftime('%Y-%m-%d %H:%m:%S'),"desc": user.description,}data.append(record)response_data['count'] = len(results_obj)response_data['data'] = datareturn JsonResponse(response_data)def user(request):"""跳转用户页面"""username = request.session['username']role = int(request.session['role'])user_id = request.session['user_id']return render(request, 'user.html', locals())def login_check(request):"""登录校验"""response_data = {}name = request.POST.get('username')password = request.POST.get('password')user = User.objects.filter(name=name, password=password).first()info = {}if user:# 将用户名存入session中request.session["username"] = user.namerequest.session["role"] = user.rolerequest.session["user_id"] = user.idresponse_data['message'] = '登录成功'return JsonResponse(response_data, status=201)else:return JsonResponse({'message': '用户名或者密码不正确'}, status=401)def edit_user(request):"""修改用户"""response_data = {}user_id = request.POST.get('id')username = request.POST.get('username')phone = request.POST.get('phone')desc = request.POST.get('desc')User.objects.filter(id=user_id).update(name=username,desc=desc,phone=phone)response_data['msg'] = 'success'return JsonResponse(response_data, status=201)def del_user(request):"""删除用户"""user_id = request.POST.get('id')result = User.objects.filter(id=user_id).first()try:if not result:response_data = {'error': '删除失败!', 'message': '找不到id为%s' % user_id}return JsonResponse(response_data, status=403)result.delete()response_data = {'message': '删除成功!'}return JsonResponse(response_data, status=201)except Exception as e:response_data = {'message': '删除失败!'}return JsonResponse(response_data, status=403)def change_password(request):"""修改密码"""old_pwd = request.POST.get('password1')username = request.session["username"]user_obj = User.objects.filter(name=username).first()if user_obj.password == old_pwd:User.objects.filter(name=username).update(password=request.POST.get('password2'))return JsonResponse({'msg': '修改成功!', 'error': 0})else:return JsonResponse({'msg': '旧密码不正确,请重新输入', 'error': 403})