參考博客 -陳曉梅 http://www.cnblogs.com/c-x-m/p/9025478.htmlhtml
登陸viewdjango
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': '銷售經理'}]>session
ret2 =user_obj.roles.all().values("title",'permissions__url',"permissions__title") print(ret2)
<QuerySet ide
[{'title': '銷售員', 'permissions__url': '/users/', 'permissions__title': '查看用戶'},url
{'title': '銷售員', 'permissions__url': '/orders/', 'permissions__title': '查看訂單'}, spa
{'title': '銷售經理', 'permissions__url': '/users/', 'permissions__title': '查看用戶'},code
{'title': '銷售經理', 'permissions__url': '/users/edit/(\\d+)', 'permissions__title': '編輯用戶'}, htm
{'title': '銷售經理', 'permissions__url': '/orders/add/', 'permissions__title': '添加訂單'}]>blog