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'])
명령 인수는로 설정 url
되지 않습니다 args
. 하다:
call_command("dummy", url='google.com')
Django 관리 명령 argparse
은 인수 구문 분석에 사용 됩니다. 관통 이동 문서 방법이 작품에 대한 아이디어를 얻을.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다