我正在尝试在我的views.py中使用@action decorator,但没有被识别。它是不推荐的还是什么
class CategoryTargetGroupDelete(APIView):
queryset = CategoryTargetGroup.objects.all()
@action(detail=False, methods=['delete'])
def delete(self, request):
cat_id = request.query_params['cat_id']
queryset = CategoryTargetGroup.objects.filter(category=cat_id)
queryset.delete()
return Response(serializer.data)
我已尝试导入操作
DRF 3.7.1
Python 3.9
我认为您可能没有导入操作
试一试
@action
版本3.8.0中的rest_框架添加了^decorator。您可以增加rest_框架版本或使用@detail_route
或@list_route
代替@action
装饰器更多详情here
如果没有像drf版本这样的附加信息,那就有点难了。 但你能从这里得到行动吗
相关问题 更多 >
编程相关推荐