Django while running the server ModuleNotFoundError: No module named 'customer data'

I'm using django to make an API that connects to another one to get some data and update some values. The idea is that the api can be executed from a CLI through commands like upgrade customer_id target_subscription.

Before making the CLI file, the api works perfectly if you make requests to it (for example using vs code's thunder client). Once I make the CLI file and try to test I get the following error:

enter image description here

Im running the code on Windows 10 and WSL bash. I create the django project using:

django-admin startproject customer_data
cd customer_data
python manage.py startapp customer

My file/folder strucutre is this:

enter image description here

My API code:

class UpdateCustomerSubscriptionView(APIView):

    def extractCustomerData(self, customer_id):
        """
        Input: A customer id
        Output: The customer data
        """
        customer = None
        try:
            response = requests.get(f'{API_LINK}{customer_id}/')
            customer_data = response.json()
            customer = Customer(**customer_data)
        except:
            return Response({"error": "The ID does not exist or is badly formated."}, status=500)
        return customer

    def upgrade_or_downgrade(self, customer_id, target_subscription):
        """
        Input: A customer id and a target subscription level
        Output: The updated customer data
        """
        # Validate that the id is not null
        if customer_id is None:
            return Response({"error": "The customer id is null."}, status=500)
        # Validate that the new subscription is not null
        if target_subscription is None:
            return Response({"error": "The target subscriptiond is null."}, status=500)
        # Validate that the new subscription is valid.
        if target_subscription not in SUBSCRIPTION_CHOICES:
            return Response({"error": "The target subscription level is not reachable."}, status=500)

        # Get customer data from the external API
        customer = self.extractCustomerData(customer_id)
        if isinstance(customer, Response):
            return customer

        # Update the customer's subscription level
        customer.data['SUBSCRIPTION'] = target_subscription
        customer_data = model_to_dict(customer)
        customer_data['id'] = customer.id
        data_json = json.dumps(customer_data)
        headers = {'content-type': 'application/json'}
        # Making the PUT request to customerdataapi
        r = requests.put(f'{API_LINK}{customer_id}/', data=data_json, headers=headers)
        print(r.status_code)
        return Response(customer_data, status=200)

    def post(self, request):
        # Get customer id and target subscription level from the request body
        customer_id, target_subscription = sys.argv[1], sys.argv[2]
        print(customer_id, target_subscription)
        return self.upgrade_or_downgrade(customer_id, target_subscription)

My CLI file looks like this:

if [ "setup" == $1 ]; then
    echo "Running setup"
    # Replace this with any commands you need to setup your code
    # pip install -r requirements.txt
    exit;
fi

if [ "upgrade" == $1 ]; then
    echo "Upgrading with args: ${@:2}"
    # Use this line to call your code
    export DJANGO_SETTINGS_MODULE="customer_data.settings"
    python customer_data/customer/views.py upgrade ${@:2} || python3 customer_data/customer/views.py upgrade ${@:2}
    exit;
fi

if [ "downgrade" == $1 ]; then
    echo "Downgrading with args: ${@:2}"
    # Use this line to call your code
    export DJANGO_SETTINGS_MODULE="customer_data.settings"
    python customer_data/customer/views.py downgrade ${@:2} || python3 customer_data/customer/views.py downgrade ${@:2}
    exit;
fi

echo "Your first argument must be either 'setup', 'upgrade' or 'downgrade'"
exit 5;

I try this but doesnt work. In my setting.py file in INSTALLED_APPS I add 'customer' and 'rest_framework'. Thank you in advance for your help, any other information you need, please let me know.

Back to Top