day 90 RBAC
参考博客 -陈晓梅 http://www.cnblogs.com/c-x-m/p/9025478.html
登录view
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
from django.shortcuts import render,redirect,HttpResponse from rbac.models import * # Create your views here. def login(request): if request.method=="POST": user = request.POST.get("user") pwd =request.POST.get("pwd") user_obj = UserInfo.objects.filter(name=user,pwd=pwd).first() print(user_obj) if user_obj: request.session["user_id"] = user_obj.pk ret1 =user_obj.roles.all().values("title") print(ret1) ret2 =user_obj.roles.all().values("title",'permissions__url',"permissions__title") print(ret2) return HttpResponse("登录成功!") else: return redirect("/login/") return render(request, "login.html")
ret1 =user_obj.roles.all().values("title") print(ret1)
<QuerySet [{'title': '销售员'}, {'title': '销售经理'}]>
ret2 =user_obj.roles.all().values("title",'permissions__url',"permissions__title") print(ret2)
<QuerySet
[{'title': '销售员', 'permissions__url': '/users/', 'permissions__title': '查看用户'},
{'title': '销售员', 'permissions__url': '/orders/', 'permissions__title': '查看订单'},
{'title': '销售经理', 'permissions__url': '/users/', 'permissions__title': '查看用户'},
{'title': '销售经理', 'permissions__url': '/users/edit/(\\d+)', 'permissions__title': '编辑用户'},
{'title': '销售经理', 'permissions__url': '/orders/add/', 'permissions__title': '添加订单'}]>