Django manage.py --no-input . 是或否?

24

我在文档中找不到这个信息。当我运行python manage.py collecstatic --no-input时,这是否意味着它会自动回答弹出的任何提示?对于python manage.py migrate --no-input也是同样的情况。


1
我认为一般来说,答案是“是”,但我之前注意到过它无法删除陈旧内容类型的错误。https://code.djangoproject.com/ticket/25036 - wim
1个回答

40

对于 collectstatic:

    message.append(
        'Are you sure you want to do this?\n\n'
        "Type 'yes' to continue, or 'no' to cancel: "
    )

    if self.interactive and input(''.join(message)) != 'yes':
        raise CommandError("Collecting static files cancelled.")

对于collect static,如果你设置了--no-input,它会将interactive设置为False,并且,如上所示,会为您回答问题,回答为yes

对于迁移(migrate)来说更加棘手,因为涉及到 Django 的信号处理。管理命令migrate本身不会询问任何问题,但是其他安装的应用程序可能会连接到pre_migrate_signalpost_migrate_signal,以自己的方式处理交互性。我所知道的最常见的是contenttypes

对于contenttypes--no-input的答案是"no",意思是"不,请不要删除任何过期的内容类型":

        if interactive:
            content_type_display = '\n'.join(
                '    %s | %s' % (ct.app_label, ct.model)
                for ct in to_remove
            )
            ok_to_delete = input("""The following content types are stale and need to be deleted:

%s

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: """ % content_type_display)
        else:
            ok_to_delete = False

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接