Using django 1.5
I want to use a shell script to run a custom django manage.py command while I'm passing in the settings (i.e. not using the settings from the same directory).
As an example of passing in my settings, if I run my django development server I'd do so like this:
python manage.py runserver ip:port --settings=my.namespace.settings
In the same directory as my manage.py file, I have my shell script: myscript
Current contents of myscript:
#!/bin/bash
./manage.py shell --settings=my.namespace.settings
From the directory of myscript, running ./myscript does indeed give me the django shell with the context of the correct app settings (I've verified that by putting a custom variable, TEST_VAR, in my app settings and it outputs correctly in the django shell via from django.conf import settings > settings.TEST_VAR).
Now I change myscript to run my custom command:
#!/bin/bash
./manage.py custom_command --settings=my.namespace.settings
PROMPT: Unknown command: 'custom_command'
I've followed these instructions to create my custom django command.
My directory structure looks as such:
my.namespace
__init__.py // & other django app files/dirs
management // directory
__init__.py
commands // directory
__init__.py
custom_command.py
custom_command.py:
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
args = 'test'
help = 'test help'
def handle(self, *args, **kwargs):
print 'test'
Again, running myscript gives me unknown command. Any ideas?
handle()into the class? Also have you tried running the command "by hand" first?gives me errors about not having django environment variablesusually when I get errors like those it's because I'm not sourced into my virtual environment. Are you using virtualenv?