Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 636 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
django custom command not found

#1
Having issues getting django custom commands to work.

From django <a href="http://docs.djangoproject.com/en/dev/howto/custom-management-commands/">documetation</a>, 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'
Reply

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

#3
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
Reply

#4
If the project is byte-compiled, django.core.management.find_commands() will only look for .py files. If your custom commands are in .pyc files, you need to patch django/core/management/commands/\__init__.py with the patch at

[To see links please register here]

Reply

#5
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.
Reply

#6
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 ...
)
Reply

#7
Hi I also had this problem and found out I was mixing up the argument identifier with the file name

so the file is the name of the command you want i.e. <code>updater</code> I changed <b>updatefiles.py</b> to <b>updater.py</b>


class Command(BaseCommand):
help = 'Update Files Since \'X\' Days Ago'

def add_arguments(self, parser):
parser.add_argument('updatefiles', nargs='+', type=int)

def handle(self, *args, **options):

days_ago = int(options['updatefiles'][0])
days_ago = (days_ago * -1) if days_ago < 0 else days_ago

self.stdout.write('Adding files since %s days ago' % days_ago)
add_files_function(days_ago)


then to run I would use

python manage.py updater
Reply

#8
I had this same problem. I had cut and paste the filename from an example and had paste a space at the start of the filename. Therefore Django could not find it.
Reply

#9
My problem was I was adding the management directory in my main app besides my settings.py file once I have added it to another app it worked
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through