rednaxela
rednaxela

Reputation: 781

Django custom command - Not Implemented Error

I'm trying to set up a cronjob on my Ubuntu server to run a django .py file - but I'm having trouble running the script first.

I'm using the command python3 /opt/mydir/manage.py updatefm

which produces the error:

File "/opt/mydir/manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 324, in handle
    raise NotImplementedError()
NotImplementedError

Can anybody enlighten my on what I'm doing incorrect? Here is my script and structure:

/mydir
   /mydir
      __init__.py
      /management
         __init__.py
         /commands
            updatefm.py

updatefm.py

class Command(BaseCommand):
    args = ''
    help = 'Help Test'
    def update_auto(self, *args, **options):
        hi = 'test'

My app name is listed in settings.py as it should be.

Upvotes: 0

Views: 1449

Answers (2)

Daniel Kravetz Malabud
Daniel Kravetz Malabud

Reputation: 783

Classes inheriting from BaseCommand must implement the method handle.

In your case, you should change

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

to

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

Upvotes: 1

itzMEonTV
itzMEonTV

Reputation: 20349

Check __init__.py inside commands folder. Then you have to use handle method

class Command(BaseCommand):
    args = ''
    help = 'Help Test'
    def handle(self, *args, **options):
        hi = 'test

For more info https://docs.djangoproject.com/en/dev/howto/custom-management-commands/#django.core.management.BaseCommand.handle

Upvotes: 1

Related Questions