Django检查用户组权限 [英] Django check user group permissions

查看:60
本文介绍了Django检查用户组权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有名称='可以显示分发页面',代号=' 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.

推荐答案

做到这一点的正确方法是使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆