1

同じ管理コマンド クラス オプションを使用して、引数の有無にかかわらず実行することは可能ですか。

if args == "" (このコマンドを実行) else: (これを実行)?

前もって感謝します。

4

1 に答える 1

3

確かに、次のようにhandleメソッドに渡される'args'を確認してください。

from django.core.management.base import BaseCommand

class Command(BaseCommand):
    help = 'prints no args if there are no args'

    def handle(self, *args, **options):
        if len(args) == 0:
            print 'no args'
        else:
            for pkid in args:
                print pkid
于 2013-02-25T21:41:23.800 に答える