python - 如何使用带有 -l 或 --no input 等选项的 call_command 以编程方式调用 collectstatic 管理命令

标签 python django

我正在尝试使用 call_command 调用 collectstatic 命令,但是当我想使用像 -l 或 --noinput 这样的选项时

django.core.management.call_command('collectstatic','--noinput')

它给我一个错误

CommandError: Command doesn't accept any arguments

请告诉我如何调用它,如何传递这个选项。

提前致谢

最佳答案

这在 Django 的官方文档中有所介绍:( https://docs.djangoproject.com/en/1.8/ref/django-admin/#running-management-commands-from-your-code ) 调用命令的正确方法应该是:

from django.core.management import call_command

call_command('collectstatic', verbosity=0, interactive=False)

关于python - 如何使用带有 -l 或 --no input 等选项的 call_command 以编程方式调用 collectstatic 管理命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29912251/

相关文章:

python - 函数 font_back - 错误

python - 仅取 pandas 中两个连续值的平均值

python - 使用 Youtube-dl 将缩略图嵌入到 mp3 引发异常

python - Python中lambda函数的哈希

jquery - 在渲染的 HTML 中标记复选框

python - 将 2 列数据框转换为多级分层数据框

python - 在 django 模板中显示列表

django - 在 Django 中制作 A-Z 列表的最佳方法?

jquery - 通过 jQuery 订购 django 更改列表页面?

python - 重写 Django ModelForm 中的 save() 方法来创建或更新