设置 user_permissions 时 Django 用户 get_all_permissions() 为空 [英] Django user get_all_permissions() is empty while user_permissions is set

查看:27
本文介绍了设置 user_permissions 时 Django 用户 get_all_permissions() 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I added some permissions to a user via the admin interface.

From some reason all the perm functions fail, e.g

>>> user.get_all_permissions()
set([])

But accessing the table directly, works:

>>> user.user_permissions.all()
(list of permissions as expected)

What can cause the "get_all_permissions" (and all the perm functions like has_perm()) to fail ?

Thanks

解决方案

had the same problem. I am guessing that at some point you have used a self-crafted AUTHENTICATION_BACKEND? Most examples on the net of this (INCLUDING THE DJANGO 1.0 DOCUMENTATION!) don't mention that the Backends are responsible for permissions handling as well.

However, no biggie: In whatever backend file your code resides, include this import:

from django.contrib.auth.backends import ModelBackend

Then make sure the Backend you wrote extends ModelBackend, e.g.:

class EmailBackend(ModelBackend):

Should be fine.

这篇关于设置 user_permissions 时 Django 用户 get_all_permissions() 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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