Django:从自定义命令调用标准命令
Django: call standard command from a custom command
在我的应用程序中,我使用自定义系统来管理本地化字符串。在这方面,我编写了一个生成 *.po
文件的自定义命令。但是,在 运行 该命令之后,我必须手动调用 compilemessages
命令。我想做的是从我的自定义命令中调用 compilemessages
命令。有办法吗?
您可以使用 call_command():
from django.core.management import call_command
# generate your *.po files, then
call_command('compilemessages')
在我的应用程序中,我使用自定义系统来管理本地化字符串。在这方面,我编写了一个生成 *.po
文件的自定义命令。但是,在 运行 该命令之后,我必须手动调用 compilemessages
命令。我想做的是从我的自定义命令中调用 compilemessages
命令。有办法吗?
您可以使用 call_command():
from django.core.management import call_command
# generate your *.po files, then
call_command('compilemessages')