'TypeError: QuerySet indices must be integers or slices, not str. Python

I am trying to modify the fields of the users already created and I get the following error: TypeError: QuerySet indices must be integers or slices, not str.

@api_view(['POST'])
@permission_classes([IsAuthenticated])
def update_user(request):
    user= User.objects.all()
    user_serializer= UserSerializer(user, many=True)
    print(user_serializer.data)
    user = User.objects.get(id=user['userId'])
    user.email = user['email']
    user.first_name = user['first_name']
    user.last_name = user['last_name']
    user.role = user['role']
    user.is_active = user['is_active']
    user.save(update_fields=[
        'email', 
        'first_name',
        'last_name',
        'role',
        'is_active',
    ])
    response = 'User updated correctly'
    return Response(response)

thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source