undefinedfix
Sign in

Django operation models.xxx.objecet . get (id = 1). Delete() reports an error

Menace edited in Tue, 13 Sep 2022

Problem description

Django operation models.xxx.objecet . get (id = 1). Delete() reports an error

The background of the problem and what methods have you tried

When I set up my own management interface and delete the article, there are some problems.

Related codes

// Please paste the code text below (do not replace the code with pictures) class detailview ( ViewSetMixin , APIView ):

def list(self, request, *args, **kwargs):
    pk = kwargs.get('pk')
    ret = {'code': 1000, 'data': None}
    try:
        queryset = models.BlogDetail.objects.filter(id=pk).first()
        ser = Detailserializer(instance=queryset, many=False)
        ret['data'] = ser.data
    except Exception as e:
        ret['code'] = 1001
        ret['error'] = '发生未知错误'
    return Response(ret)

def deletes(self, request, *args, **kwargs):
    pk = kwargs.get('pk')
    ret = {'code': 1000, 'data': None}
    obj = models.Blog.objects.get(id=pk).delete()
    print(obj)
    ret['data'] = '删除Blog成功'
    return Response(ret)

What are your expectations? What is the actual error message?

并没有删除而是报错,TypeError: 'bool' object is not callable
2 Replies
openHBP
commented on Tue, 13 Sep 2022

How about filter instead of get

napo
commented on Tue, 13 Sep 2022

Just take this part out of the circle