This is probably a really basic question but I can't find the answer anywhere for some reason. I created a custom command which I can call from the command line with python manage.py custom_command. I want to run it from elsewhere but don't know how to do so. I have added pages to my INSTALLED_APPS in settings.py. This question: Django custom command works on command line, but not call_command is very similar but I'm not sure what the answer means and I think it's unrelated. My file structure is :
├── custom_script
│ ├── script.py
│ ├── __init__.py
├── project
│ ├── asgi.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── pages
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── __init__.py
│ ├── management
│ │ ├── commands
│ │ │ ├── __init__.py
│ │ │ └── custom_command.py
│ │ ├── __init__.py
│ ├── migrations
│ │ ├── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
content of script.py
from django.core.management import call_command
call_command('custom_command', 'hi')
content of custom_command.py
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('message', type=str)
def handle(self, *args, **options):
print('it works')
I want to run python custom_script/script.py which will call the custom_command but keep getting: django.core.management.base.CommandError: Unknown command: 'custom_command'. I have isolated the problem to the fact that django can't see my command as when I run print(management.get_commands()) my custom command is not listed. Additionally, after looking through the django python code for management for a while I noticed this settings.configured variable which upon checking is False which means it only passes in the default commands when management.get_commands is run. How can I get this to become True? Technically, I could use a subprocess if I really wanted to but since there is already a call_command feature I figured I'd try and use it.