有没有办法检查命令是否存在?
我知道我可以写:
try:
call_command('some')
except:
print "Command does not exists"
但也许django允许检查命令是否可用?
答案 0 :(得分:3)
请参阅get_commands
:
from django.core.management import get_commands, call_command
if 'some_command' in get_commands():
call_command('some_command')