88π
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 ...
)
4π
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
- [Django]-Why does my Django admin site not have styles / CSS loading?
- [Django]-How to display the current year in a Django template?
- [Django]-Macros in django templates
4π
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
- [Django]-The QuerySet value for an exact lookup must be limited to one result using slicing. Filter error
- [Django]-How to use refresh token to obtain new access token on django-oauth-toolkit?
- [Django]-Django FileField upload is not working for me
1π
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.
- [Django]-In Django, how do you make a model refer to itself?
- [Django]-How to annotate Count with a condition in a Django queryset
- [Django]-Django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg
- [Django]-ForeignKey to abstract class (generic relations)
- [Django]-Django OneToOne reverse access
- [Django]-How can I use the variables from "views.py" in JavasScript, "<script></script>" in a Django template?
0π
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 https://code.djangoproject.com/ticket/19085
- [Django]-Django migration fails with "__fake__.DoesNotExist: Permission matching query does not exist."
- [Django]-Workflow frameworks for Django
- [Django]-How to debug in Django, the good way?
0π
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. updater
I changed updatefiles.py to updater.py
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
- [Django]-How to add an HTTP header to all Django responses
- [Django]-Celery: WorkerLostError: Worker exited prematurely: signal 9 (SIGKILL)
- [Django]-What is the Simplest Possible Payment Gateway to Implement? (using Django)
-3π
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.
- [Django]-Fastest way to get the first object from a queryset in django?
- [Django]-Get all table names in a Django app
- [Django]-Pypi see older versions of package