tags:

views:

145

answers:

2

Having issues getting django custom commands to work.

From django documetation, have placed

application/
  manage.py
  blog/
     __init__.py
     models.py
     management/
     __init__.py
    commands/
        __init__.py
        myapp_task.py
    views.py

myapp_task.py content is

from django.core.management.base import NoArgsCommand

class Command(NoArgsCommand):
    def handle_noargs(self, **options):
        print 'Doing task...'
        # invoke the functions you need to run on your project here
        print 'Done'

when ran

python manage.py myapp_task

getting error

Unknown command: 'myapp_task'
A: 

I think commands/ needs to be inside the management/ directory.

Art
commands directory is in management
bocca
A: 

The directory structure in your answer is a little ambiguous; when placing the files as follows django should be able to find your command:

project/ # in your question this would be 'application'
manage.py
blog/
   __init__.py
   models.py
   management/
       __init__.py
       commands/
           __init__.py
           myapp_task.py
   views.py

Furthermore, you'll need to enable your app in your settings.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'blog', # <= your app here ...
)
The MYYN
the file structure is correct, just got messed up pasting it here
bocca
it is listed in installed apps in settings
bocca
Bocca: Can you fix the indenting in your list of files in the original post, then? The actual structure is very important in this instance.
Jack M.
have edited to fix indenting
bocca
The indenting of the file list is still off.
Jack M.