Hi,
I’m trying to run a command in PythonAnywhere but am receiving a module not found error on exercises.
My project structure is :
exercises/management/commands/filename.py
The code is
from exercises.models import personStepCount
from django.core.management.base import BaseCommand
from datetime import datetime
####################### SCHEDULED TASKS #############################
class Command(BaseCommand):
def handle(self, *args, **options):
now = datetime.now()
day_of_week = now.isoweekday()
if day_of_week == '7':
personStepCount.objects.all().delete()
self.stdout.write("removed Person Count", ending = '')
Hoping this is something to do with my code and not to do with running these tasks in Python Anywhere
Thanks
Rob
I don’t know anything about PythonAnywhere - so I don’t know what limitations may exist with it.
But this error is generally caused by “environmental” issues, such as not having your virtual environment active or trying to run this file directly instead of through the manage.py
command.
Please show the command(s) you are using to try and run this, and what your “current directory” is when you’re doing it.
Thanks Ken, I am running this directly as the command is in the screenshot below:
So it will only work running it via manage.py?
Thanks
Rob
Correct - that’s the purpose of a management command (to be run by manage.py
).
The manage.py
file initializes the Django environment - loads the configuration, applies the settings, etc, making it possible for you to use Django features (ORM, etc) without doing that configuration yourself.
Thanks Ken that’s all sorted now,
Just for info if anyone is using python anywhere and runs into similar it can be ran by the following screenshot below: