pps*_*ith 0 python django django-1.8
from django.core.management.base import BaseCommand
def Command(BaseCommand):
def handle(self, *args, **options):
self.stdout.write( "lol" )
Run Code Online (Sandbox Code Playgroud)
所以我尝试在Django 1.8中创建一个自定义命令.它位于appname/management/commands/commandname.py目录中.但是,尝试使用以下命令运行命令:
python manage.py commandname
Run Code Online (Sandbox Code Playgroud)
产生了这个错误:
TypeError: Command() takes exactly 1 argument (0 given)
Run Code Online (Sandbox Code Playgroud)
我确保所有目录都包含__ init__.py文件,并且应用程序已添加到项目中.在线上似乎没有太多信息.请帮忙.
根据此文档页面(https://docs.djangoproject.com/en/1.8/howto/custom-management-commands/),您可能希望将该行更改def Command(BaseCommand):
为class Command(BaseCommand):
.(看起来还需要进行一些进一步的改动)