按照文档: https ://docs.djangoproject.com/en/dev/howto/custom-management-commands/
我创建了自己的自定义命令(称为其他命令,但示例如下所示):
from django.core.management.base import BaseCommand, CommandError
from polls.models import Poll
class Command(BaseCommand):
args = '<poll_id poll_id ...>'
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
for poll_id in args:
try:
poll = Poll.objects.get(pk=int(poll_id))
except Poll.DoesNotExist:
raise CommandError('Poll "%s" does not exist' % poll_id)
poll.opened = False
poll.save()
self.stdout.write('Successfully closed poll "%s"' % poll_id)
return "Yay"
问题是为什么返回像“Yay”这样的字符串不起作用?我做错了还是不可能?
当我从视图中调用自定义命令时,我会执行以下操作:
value = call_command('call_custom_command', parameter)
print value
但该值显示为无。