Django manage.py --no-input。是还是不是?

时间:2017-01-30 18:43:23

标签: django django-manage.py

我无法在文档中找到这个。当我运行python manage.py collecstatic --no-input时,它意味着它会回答"是"任何会在此过程中弹出的提示? python manage.py migrate --no-input也是如此。

1 个答案:

答案 0 :(得分:27)

您可以随时查看django源代码。你知道,它是开源的。

对于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.")

因此,对于收集静态,如果您设置--no-input,则会将interactive设置为False,正如您在上面看到的那样,将为您回答yes的问题

对于迁移,由于django信令,它更加棘手。 migrate管理本身不会提出任何问题,但其他已安装的应用可能会挂钩pre_migrate_signalpost_migrate_signal并以自己的方式处理互动。我所知道的最常见的是contenttypes

对于contenttypes--no-input回答"否"在"不,请不要删除任何过时的内容类型":

        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