django组权限 [英] django group permission
问题描述
我添加了一个权限,其名称为='可以显示分发页面',代号='can_show_distribute_page',contenttype ='用户'.
I add a permission with name = 'can show distribute page', codename='can_show_distribute_page', contenttype='user'.
我添加了两个组,分别名为"manager"和"normal",一组具有"can_show_distribute_page"的权限,而另一组则没有.
I add two groups, named 'manager' and 'normal', one has the permission 'can_show_distribute_page' and one not.
现在我添加了两个用户,一个添加了"manager"组,另一个添加了"normal"组,如何判断用户是否具有权限can_show_distribute_page?我尝试使用has_perm方法,但它始终返回False.
Now I add two users, one adds the group 'manager', the other 'normal', how to judge whether a user has the permssion can_show_distribute_page? I try to use the has_perm method, but it always returns False.
推荐答案
正确的方法是使用 get_group_permissions
来查看他们通过其组成员身份实际拥有的权限.
The correct way to do this is to use has_perm
on the User class. If this is not working, check to make sure that both users are set as active. If that does not seem to be the problem, bring up each user in the shell and call get_group_permissions
to see what permissions they actually have through their group memberships.
这篇关于django组权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!