Django:管理员通知,如果是超级用户则显示

3

我有一些问题需要帮助

我正在使用 django-admin-notifications 在我的管理面板中显示通知,我希望它在用户是超级用户时显示

这是我的 admin.py 代码:

def get_user_perm(request): 
    if not request.user.is_superuser:
        return True
    else:
        return False

def notification():
    if get_user_perm:

        return "Working"
    else:
        return "Still working"
admin_notifications.register(notification)

不管用户是谁,它仍然会显示“True”或者“Working”。

我被卡住了,不知道该怎么办,非常感谢您的帮助。

更新

尝试打印值。

print get_user_perm

它说:(function user_perm at 0x00000000033384A8)

尝试添加request

def notification(request):
    if get_user_perm(request):

        return "Working"
    else:
        return "Still working"
admin_notifications.register(notification)

但是它显示notification()需要1个参数,但是没有给出


是的,因为你在没有调用函数的情况下打印了它。你应该使用一个有效的请求对象在括号中执行 print get_user_perm(request) - danidee
是的,我已经搜索过了,应该是这样的,但是添加请求会给我一个错误,我不知道该怎么办。 - Juan Carlos Asuncion
1个回答

0
尝试添加括号:

get_user_perm()


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接