Django自定义命令 - 未实现错误

时间:2016-08-31 19:15:59

标签: python django python-3.x

我正在尝试在我的Ubuntu服务器上设置一个cronjob来运行django .py文件 - 但是我首先运行该脚本时遇到了问题。

我正在使用命令python3 /opt/mydir/manage.py updatefm

产生错误:

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

任何人都可以启发我的错误吗?这是我的脚本和结构:

/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'

我的应用名称列在settings.py中。

2 个答案:

答案 0 :(得分:1)

检查__init__.py文件夹中的commands。然后你必须使用handle方法

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

了解更多信息https://docs.djangoproject.com/en/dev/howto/custom-management-commands/#django.core.management.BaseCommand.handle

答案 1 :(得分:1)

BaseCommand继承的类必须实现方法handle

在您的情况下,您应该更改

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

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