{"id":8956,"library":"django-rich","title":"django-rich","description":"django-rich is a Python library that provides extensions for integrating the Rich library with Django projects. It enhances the Django development experience by enabling Rich's pretty-printing in the Django shell, providing Rich-powered tracebacks for the test runner, and offering a `RichCommand` base class for creating visually appealing management commands. The library is currently at version 2.2.0 and receives regular updates to support the latest Django and Python versions.","status":"active","version":"2.2.0","language":"en","source_language":"en","source_url":"https://github.com/adamchainz/django-rich","tags":["Django","Rich","CLI","Developer Tools","Debugging","Management Commands","Testing","Console"],"install":[{"cmd":"pip install django-rich","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core dependency for rich text formatting and console output.","package":"rich","optional":false},{"reason":"The framework this library extends.","package":"Django","optional":false}],"imports":[{"note":"Use RichCommand as a base for Django management commands to get integrated console features, including colorization based on Django's --no-color/--force-color flags.","wrong":"from rich.console import Console # Directly instantiating Console without RichCommand context","symbol":"RichCommand","correct":"from django_rich.management import RichCommand"},{"note":"Adding 'django_rich' to INSTALLED_APPS activates the enhanced Django shell and Rich tracebacks in the test runner.","symbol":"django_rich (in INSTALLED_APPS)","correct":"INSTALLED_APPS = [\n    # ...\n    'django_rich',\n    # ...\n]"}],"quickstart":{"code":"import time\nfrom django_rich.management import RichCommand\n\nclass Command(RichCommand):\n    help = \"A sample management command using django-rich.\"\n\n    def handle(self, *args, **options):\n        self.console.print(\"[bold blue]Starting a complex operation:[/bold blue]\")\n\n        with self.console.status(\"Processing items...\") as status:\n            for i in range(1, 11):\n                status.update(f\"[yellow]Processing item {i} of 10...[/yellow]\")\n                time.sleep(1)  # Simulate work\n                self.console.log(f\"[green]Item {i} processed.[/green]\")\n\n        self.console.print(\"[bold green]Operation complete![/bold green]\")\n","lang":"python","description":"This quickstart demonstrates how to create a custom Django management command that leverages `django-rich`'s `RichCommand` base class. This allows you to use `Rich`'s console, status indicators, and styled output directly within your command, inheriting Django's colorization flags. Save this as `your_app/management/commands/mycommand.py` and run `python manage.py mycommand`."},"warnings":[{"fix":"Update your `make_rich_console` override to be a standard instance method or wrap it with `staticmethod()` if it doesn't need `self`.","message":"In version 2.0.0, the `make_rich_console()` method on `RichCommand` was changed from being a `partial()` to a regular method. If you overrode this method in previous versions using `functools.partial`, your code will break.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your Django project is running on a supported version (Django 4.2 to 6.0 for django-rich 2.2.0).","message":"Version 1.13.0 dropped official support for older Django versions (3.2 to 4.1).","severity":"breaking","affected_versions":">=1.13.0"},{"fix":"Upgrade your Python environment to 3.10 or later (Python 3.10 to 3.14 are supported by django-rich 2.2.0).","message":"Version 2.1.0 dropped support for Python 3.9.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"If using IPython, refer to the official Rich documentation for IPython integration.","message":"The enhanced Django shell features (pretty-printing and automatic imports) provided by `django-rich` only apply to the standard Python interpreter and `bpython`, not `IPython`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"First, install the package: `pip install django-rich`. Then, add `'django_rich'` to your `INSTALLED_APPS` list in your Django `settings.py` file.","cause":"The `django-rich` package is either not installed in your environment or, if installed, has not been added to your Django project's `INSTALLED_APPS` setting.","error":"ModuleNotFoundError: No module named 'django_rich'"},{"fix":"If you defined `make_rich_console` using `functools.partial`, remove `partial` and implement it as a standard method. Example: `def make_rich_console(self, **kwargs): return super().make_rich_console(**kwargs, markup=False)`","cause":"This error typically occurs after upgrading `django-rich` to version 2.0.0 or later. The `make_rich_console` method, when overridden in a custom `RichCommand`, changed its signature from a `functools.partial` to a regular instance method.","error":"TypeError: Command.make_rich_console() takes 1 positional argument but 2 were given"},{"fix":"Add `'django_rich'` to your `INSTALLED_APPS` list in `settings.py`. If you're using `IPython`, `django-rich`'s shell integration will not work; consult Rich's documentation for IPython-specific setup.","cause":"The `django_rich` app is not included in your `INSTALLED_APPS` setting, or you are using `IPython` which is not directly supported by `django-rich`'s shell integration.","error":"Django shell output is not pretty-printed by Rich, or Rich functions like `inspect()` are not automatically available."}]}