From 0201b9d6d89ea277383e1fc0007bfaa33351b60b Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 9 Feb 2013 10:17:26 +0100 Subject: [PATCH] Fixed #19749 -- Documented ending param to command's self.stdout/err Thanks xian at mintchaos.com for the report. --- docs/howto/custom-management-commands.txt | 8 +++++++- docs/releases/1.5.txt | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/howto/custom-management-commands.txt b/docs/howto/custom-management-commands.txt index bfcea64b49f..7a31fc44e3c 100644 --- a/docs/howto/custom-management-commands.txt +++ b/docs/howto/custom-management-commands.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 manage.py closepoll ``. diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt index 33dcb0e794f..acf4f153ce3 100644 --- a/docs/releases/1.5.txt +++ b/docs/releases/1.5.txt @@ -253,6 +253,11 @@ Django 1.5 also includes several smaller improvements worth noting: from :ref:`call_command `. Any exception raised by the command (mostly :ref:`CommandError `) 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 `). + * The dumpdata management command outputs one row at a time, preventing out-of-memory errors when dumping large datasets.