有没有一种方法可以使用django runscript
将命令行参数传递给脚本?我试图运行的脚本使用argparse
接受命令行参数。
脚本的命令行执行:
./consumer --arg1 arg1 --arg2 arg2
arg1
和arg2
都是必需的选项。
我们尝试使用script-args
,但无法找到如何在这个上下文中使用它。
发布于 2016-09-09 07:03:31
看看Django的命令
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('--arg1', help="Something helpful")
def handle(self, *args, **options):
print options['arg1']
当奔跑时:
$python manage.py your_command --arg1 arg
arg
命令可以很好地用于这类事情,正如Selcuk所说,不能使用RunScript扩展以这种方式使用参数。
发布于 2020-05-10 10:01:42
2020年更新:使用-脚本-args
https://django-extensions.readthedocs.io/en/latest/runscript.html
https://stackoverflow.com/questions/38330829
复制相似问题