我正在尝试在 Django 2.0 中使用 args 调用该命令。当我传递参数时,它会给出以下错误消息:
“TypeError:虚拟命令的未知选项:args。有效选项有:help、no_color、pythonpath、settings、skip_checks、stderr、stdout、traceback、url、verbosity、version。”
该命令适用于选项。仅在使用 args 调用时才会导致此错误。
我的命令代码:
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'A description of your command'
def add_arguments(self, parser):
parser.add_argument(
'--url', required=False,
type=str,
help='the url to process',
)
def handle(self, *args, **options):
for url in args:
self.stdout.write(url)
这里我调用命令
from django.core.management import call_command
from django.test import TestCase
class DummyTest(TestCase):
def test_dummy_test_case(self):
call_command("dummy", args=['google.com'])