Django检查用户组权限 [英] Django check user group permissions
问题描述
我具有名称='可以显示分发页面',代号=' can_show_distribute_page ',contenttype =' User '的自定义权限
I have a custom permission with name = 'can show distribute page', codename='can_show_distribute_page', contenttype='User'.
我添加了两个组,分别为" manager "和" normal ",其中一个具有引用的权限,另一个没有.
I add two Groups, named 'manager' and 'normal', one has the cited permission and one not.
如何判断用户是否具有该权限?
我尝试使用user.has_perm()方法,但它始终返回False.
I tried to use the user.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屋!