Django manage.py --无输入。是还是不是?
Django manage.py --no-input . Yes or no?
我在文档中找不到这个。当我 运行 python manage.py collecstatic --no-input
是否意味着它会回答 "yes" 到过程中弹出的任何提示? 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
问题给你。
由于 django 信号,迁移要复杂得多。 migrate
管理本身不会询问任何问题,但其他已安装的应用程序可能会挂接到 pre_migrate_signal
或 post_migrate_signal
并以自己的方式处理交互。我知道的最常见的是 contenttypes
对于 contenttypes
,--no-input
的回答 "no" 如 "No, please don't delete any stale contenttypes":
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
我在文档中找不到这个。当我 运行 python manage.py collecstatic --no-input
是否意味着它会回答 "yes" 到过程中弹出的任何提示? 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
问题给你。
由于 django 信号,迁移要复杂得多。 migrate
管理本身不会询问任何问题,但其他已安装的应用程序可能会挂接到 pre_migrate_signal
或 post_migrate_signal
并以自己的方式处理交互。我知道的最常见的是 contenttypes
对于 contenttypes
,--no-input
的回答 "no" 如 "No, please don't delete any stale contenttypes":
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