Kaydet (Commit) d26207d5 authored tarafından Elena Oat's avatar Elena Oat Kaydeden (comit) Tim Graham

Fixed #25526 -- Documented how to output colored text in custom management commands.

üst 0a2d3b73
...@@ -67,7 +67,7 @@ look like this:: ...@@ -67,7 +67,7 @@ look like this::
poll.opened = False poll.opened = False
poll.save() poll.save()
self.stdout.write('Successfully closed poll "%s"' % poll_id) self.stdout.write(self.style.SUCCESS('Successfully closed poll "%s"' % poll_id))
.. _management-commands-output: .. _management-commands-output:
...@@ -256,6 +256,21 @@ All attributes can be set in your derived class and can be used in ...@@ -256,6 +256,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 because attempting to set the locale needs access to settings. This
condition will generate a :class:`CommandError`. 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 Methods
------- -------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment