single |
===========
django-rich
===========
:alt: pre-commit
Extensions for using [Rich] with Django.
----
**Work smarter and faster** with my book [Boost Your Django DX] which
covers many ways to improve your development experience.
I wrote django-rich whilst working on the book!
----
Requirements
------------
Python 3.9 to 3.14 supported.
Django 4.2 to 6.0 supported.
Installation
------------
1. Install with **pip**:
.. code-block:: sh
python -m pip install django-rich
None of django-rich’s features are activated by default.
Follow the documentation below to use them.
Reference
---------
shell command integration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-rich has an extended version of Django’s built-in |shell
command|__ that does two things:
1. It enables `Rich’s pretty-printing
`__.
2. On Django 5.2+, it adds [automatic imports] of these functions from
Rich:
* |inspect()|__
.. |inspect()| replace:: ``inspect()``
__
https://rich.readthedocs.io/en/stable/introduction.html#rich-inspect
* |print()|__
.. |print()| replace:: ``print()``
__ https://rich.readthedocs.io/en/stable/introduction.html#quick-start
* |print_json()|__
.. |print_json()| replace:: ``print_json()``
__ https://rich.readthedocs.io/en/stable/console.html#printing-json
* |pprint()|__
.. |pprint()| replace:: ``pprint()``
__ https://rich.readthedocs.io/en/stable/pretty.html#pprint-method
To activate this feature, add django_rich to your INSTALLED_APPS setting:
.. |shell command| replace:: shell command
__ https://docs.djangoproject.com/en/stable/ref/django-admin/#shell
.. code-block:: python
INSTALLED_APPS = [
...,
"django_rich",
...,
]
This feature only affects the Python and bypthon interpreters, not IPython.
For IPython support, see [the Rich documentation].
``django_rich.management.RichCommand``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A subclass of Django’s |BaseCommand|__ class that sets its
``self.console`` to a Rich |Console|__.
The Console uses the command’s stdout argument, which defaults to
``sys.stdout``.
Colourization is enabled or disabled according to Django’s ``--no-color
and --force-color`` flags.
.. |BaseCommand| replace:: BaseCommand
__
https://docs.djangoproject.com/en/stable/howto/custom-management-commands/#django.core.management.BaseCommand
|