FunLovinCoder
FunLovinCoder

Reputation: 7877

Django: Can't run custom commands

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'

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?

Upvotes: 11

Views: 9874

Answers (3)

Fravel
Fravel

Reputation: 177

To solve the issue: I move the management folder one level up in my folder tree. In other words, in the same folder as settings.py

Upvotes: 0

maQbex
maQbex

Reputation: 21

It is because the __init__.pyc does not get created automatically within "management" and "commands" folder. Copy your_app/__init__.py and your_app/__init__.pyc and paste it within the management/ and commands/ folder.

Upvotes: -2

FunLovinCoder
FunLovinCoder

Reputation: 7877

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.

Upvotes: 8

Related Questions