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