0

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.

6
  • You seem to be missing a __init__.py inside your /commands directory. Also, I'm not a 100% sure, but I believe you should import said command as well in your manage.py Commented Aug 31, 2016 at 19:21
  • I think in the documentation it says I only need __init__.py in /commands directory if i'm using python2 docs.djangoproject.com/en/1.7/howto/custom-management-commands/… Commented Aug 31, 2016 at 19:25
  • 1
    NotImplementedError means you haven't implemented the full API for a subclass and the parent class can't do it for you. It's being raised by the handle method. You don't implement that. Seems like you should. Commented Aug 31, 2016 at 19:25
  • @rednaxela, a quote from the docs : "On Python 2, be sure to include init.py files in both the management and management/commands directories as done above or your command will not be detected." Commented Aug 31, 2016 at 19:26
  • @Av4t4r I'm using python3 Commented Aug 31, 2016 at 19:29

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh, I didn't realise it actually had to be named handle(). thanks
1

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):

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.