django group permission

孤者浪人 提交于 2019-12-10 23:47:27

问题


I add a permission with name = 'can show distribute page', codename='can_show_distribute_page', contenttype='user'.

I add two groups, named 'manager' and 'normal', one has the permission 'can_show_distribute_page' and one not.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/16474235/django-group-permission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!