Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Can't run custom commands

Tags:

python

django

I've written a simple custom command, hello.py:

from django.core.management.base import NoArgsCommand

class Command(NoArgsCommand):
    help = "prints hello world"

    def handle_noargs(self, **options):
        print "Hello, World!"

When I run python manage.py hello it returns

Unknown command: 'hello'

  • I've put it in the management/commands directory beneath my app.
  • I've added __init__.py files to the management and commands directory.
  • I've checked my app is in INSTALLED_APPS in settings.py
  • I've tried installing it in different apps and from the project root too

Running python manage.py syncdb etc is fine. And if I type python at the command line I can import django.core.management ok.

I know I'm missing something obvious, but can't figure out what.

How can I debug this to work out why my custom command won't run?

like image 751
FunLovinCoder Avatar asked Nov 28 '10 10:11

FunLovinCoder


People also ask

How do I fix Django admin not recognized?

To fix this, first close the terminal window and relaunch it with administrator privileges. Once you launch the elevated terminal window change directory to where you wish to start your Django project. The command should work.


1 Answers

The problem was that I had another project on my PYTHONPATH. D'oh! I think it was picking up the settings.py from there first so didn't see my app. What pointed me in this direction was I tried running python manage.py create_jobs myapp (from django command extensions) and it returned an error indicating the app couldn't be found. Also @knutin mentioned INSTALLED_APPS.

like image 96
FunLovinCoder Avatar answered Oct 13 '22 10:10

FunLovinCoder