Browse files

[1.5.x] Fixed #19749 -- Documented ending param to command's self.std…


Thanks xian at for the report.
Backport of 0201b9d from master
  • Loading branch information...
1 parent 15796db commit 2d53799ca6674de39b5d3ac66c28b434d079725c @claudep claudep committed Feb 9, 2013
Showing with 12 additions and 1 deletion.
  1. +7 −1 docs/howto/custom-management-commands.txt
  2. +5 −0 docs/releases/1.5.txt
@@ -65,12 +65,18 @@ look like this:
self.stdout.write('Successfully closed poll "%s"' % poll_id)
+.. _management-commands-output:
.. note::
When you are using management commands and wish to provide console
output, you should write to ``self.stdout`` and ``self.stderr``,
instead of printing to ``stdout`` and ``stderr`` directly. By
using these proxies, it becomes much easier to test your custom
- command.
+ command. Note also that you don't need to end messages with a newline
+ character, it will be added automatically, unless you specify the ``ending``
+ parameter::
+ self.stdout.write("Unterminated line", ending='')
The new custom command can be called using ``python closepoll
@@ -253,6 +253,11 @@ Django 1.5 also includes several smaller improvements worth noting:
from :ref:`call_command <call-command>`. Any exception raised by the command
(mostly :ref:`CommandError <ref-command-exceptions>`) is propagated.
+ Moreover, when you output errors or messages in your custom commands, you
+ should now use ``self.stdout.write('message')`` and
+ ``self.stderr.write('error')`` (see the note on
+ :ref:`management commands output <management-commands-output>`).
* The dumpdata management command outputs one row at a time, preventing
out-of-memory errors when dumping large datasets.

0 comments on commit 2d53799

Please sign in to comment.