1 def login(request): 2 if request.method == 'GET': 3 return render(request, 'login.html') 4 5 user = request.POST.get('user') 6 pwd = request.POST.get('pwd') 7 obj = models.UserInfo.objects.filter(name=user, password=pwd).first() 8 9 if not obj: 10 return render(request, 'login.html', {'msg': '用户名或密码错误'}) 11 permission_queryset = obj.role.filter(permission__url__isnull=False).values('permission__url', 12 'permission__title', 13 'permission__is_menu', 14 'permission__icon').distinct() 15 menu_list = [] 16 permission_list = [] 17 for item in permission_queryset: 18 permission_list.append({'permission_url': item['permission_url']}) 19 if item['permission__is_menu']: 20 menu_list.append({'icon': item['permission__icon'], 21 'title': item['permission__title'], 22 'url': item['permission__url']}) 23 request.session['user_info'] = {'id': obj.id, 'name': obj.name} 24 request.session['permission_list'] = permission_list 25 request.session['menu_list'] = menu_list 26 27 return HttpResponse('...')