Django-user_passes_test身份验证修饰器-\'bool\'对象不可调用

问题描述

| 嗨,我正在尝试使用此处提到的user_passes_test装饰器。但我不断收到此错误:
\'bool\' object is not callable
我的用法:
@user_passes_test(lambda u: u.is_active() and u.is_staff())
def fulfillment(request):
    ...
    

解决方法

is_staff是用户字段而不是方法。摆脱 ()     ,另一种情况,如果您编写这样的代码:
newFile = open(\'pickled\',\'w\')
pickle.dump(newText,newFile)
newFile.closed()
如您所见,“ 3”会触发相同的错误,“ 4” 原因:ѭ3是布尔值...并且已分配给变量,方程式或其他内容...     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...