Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django custom command not found

Tags:

django

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' 
like image 608
bocca Avatar asked Feb 03 '10 08:02

bocca


People also ask

How do you pass arguments in Django management command?

In order to use arguments in a custom Django management command, you must also declare the add_arguments() method. The add_arguments() method must define a management task's arguments, including their type -- positional or named -- default value, choice values and help message, among other things.

What is Django command?

Some of the most commonly used commands are – python manage.py startapp. python manage.py makemigrations. python manage.py migrate. python manage.py runserver.


2 Answers

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 ... ) 
like image 170
miku Avatar answered Sep 24 '22 11:09

miku


I had the same problem. The reason was that the project root was not in my $PYTHONPATH. The solution in this case is to type (on a Linux machine) something like

PYTHONPATH=./project python manage.py myapp_task 
like image 35
Philipp Zedler Avatar answered Sep 26 '22 11:09

Philipp Zedler