but all I got is an empty string in my out.getvalue().
From what I understand from Django code here, it does not capture the output (ie: sys.stdout.write("blah blah")) but the return value of my command. It doesn't make sense to me, there's no point returning a value in a management command.
Am I missing something? Is the documentation wrong or is it a bug ?
Michal Petrucha
unread,
Jan 20, 2016, 6:20:24 AM1/20/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
> returning a value in a management command.
>
> Am I missing something? Is the documentation wrong or is it a bug ?
Hi Patrice,
Returning a value from a management command's ``handle`` method is
documented [1], though it might only be useful in very specific
situations (namely, when your management command produces SQL code).
The problem you're facing is that your management command writes
directly to ``sys.stdout`` instead of ``self.stdout`` as indicated in
the docs [2]. If you change your management command to use
``self.stdout``, it should work as you expect.