summaryrefslogtreecommitdiff
path: root/docs/howto
diff options
context:
space:
mode:
authorElena Oat <elena@rategia.com>2015-11-08 10:47:21 +0100
committerTim Graham <timograham@gmail.com>2015-11-17 18:24:10 -0500
commit43da3179a46c9000532a46674424923d98f5434b (patch)
treecac8e0a12d2f7a5cda5c3f2aeb6fb797bb589098 /docs/howto
parent361038ee03b3b8513470990fc1851a51f56ecd6c (diff)
[1.9.x] Fixed #25526 -- Documented how to output colored text in custom management commands.
Backport of d26207d56cab21e3767121d53ebaddbbfc78a4ce from master
Diffstat (limited to 'docs/howto')
-rw-r--r--docs/howto/custom-management-commands.txt17
1 files changed, 16 insertions, 1 deletions
diff --git a/docs/howto/custom-management-commands.txt b/docs/howto/custom-management-commands.txt
index 833bc3840d..341dd6a5a3 100644
--- a/docs/howto/custom-management-commands.txt
+++ b/docs/howto/custom-management-commands.txt
@@ -67,7 +67,7 @@ look like this::
poll.opened = False
poll.save()
- self.stdout.write('Successfully closed poll "%s"' % poll_id)
+ self.stdout.write(self.style.SUCCESS('Successfully closed poll "%s"' % poll_id))
.. versionchanged:: 1.8
@@ -303,6 +303,21 @@ All attributes can be set in your derived class and can be used in
because attempting to set the locale needs access to settings. This
condition will generate a :class:`CommandError`.
+.. attribute:: BaseCommand.style
+
+ An instance attribute that helps create colored output when writing to
+ ``stdout`` or ``stderr``. For example::
+
+ self.stdout.write(self.style.SUCCESS('...'))
+
+ See :ref:`syntax-coloring` to learn how to modify the color palette and to
+ see the available styles (use uppercased versions of the "roles" described
+ in that section).
+
+ If you pass the :djadminopt:`--no-color` option when running your
+ command, all ``self.style()`` calls will return the original string
+ uncolored.
+
Methods
-------