Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 类型错误:';布尔';对象不可调用_Python_Python 3.x_Django_Django Rest Framework - Fatal编程技术网

Python 类型错误:';布尔';对象不可调用

Python 类型错误:';布尔';对象不可调用,python,python-3.x,django,django-rest-framework,Python,Python 3.x,Django,Django Rest Framework,我有一个配置文件模型,我希望只有该配置文件的所有者可以看到它并更新它。我正在写我自己的许可,但我有那个错误我该怎么办??类型错误:“bool”对象不可调用 #views.py class ProfileRetrieveUpdateView (generics.RetrieveUpdateAPIView): queryset = Profile.objects.all() serializer_class = ProfileSerializer permission_cla

我有一个配置文件模型,我希望只有该配置文件的所有者可以看到它并更新它。我正在写我自己的许可,但我有那个错误我该怎么办??类型错误:“bool”对象不可调用

#views.py
class ProfileRetrieveUpdateView (generics.RetrieveUpdateAPIView):
    queryset = Profile.objects.all()
    serializer_class = ProfileSerializer
    permission_classes = (IsOwner,)



#permissions
class IsOwner(permissions.BasePermission):
    """
    Custom permission to only allow owners of an object to edit it.
    """
    def has_permission(self, request, view):
        return request.user and request.user.is_authenticated()

    def has_object_permission(self, request, view, obj):
        return obj.user == request.user
试试这个

class IsOwner(permissions.BasePermission):
    """
    Custom permission to only allow owners of an object to edit it.
    """
    def has_permission(self, request, view):
        return request.user and request.user.is_authenticated

    def has_object_permission(self, request, view, obj):
        return obj.user == request.user

错误在哪一行?在这一行:return request.user和request.user.is_authenticated()我发现了问题,谢谢。我应该删除()是的,它有效。请给我的问题打分,以帮助其他人解决同样的问题,我获得了声誉。好的,这已经在文档中提到了。django 1.8之后,is_身份验证标识符从函数更改为属性。