Skip to main content

Extensions for using Rich with Django.

Project description

https://img.shields.io/github/workflow/status/adamchainz/django-rich/CI/main?style=for-the-badge https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge https://img.shields.io/pypi/v/django-rich.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit

Extensions for using Rich with Django.

Requirements

Python 3.6 to 3.10 supported.

Django 2.2 to 4.0 supported.


Are your tests slow? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.


Installation

  1. Install with pip:

    python -m pip install django-rich

Reference

django_rich.management.RichCommand

A subclass of Django’s BaseCommand class that sets its self.console to a Rich Console. It tries to correctly enable/disable colourization based on Django’s --no-color and --force-color flags. Use this for Rich output in your management commands.

For example:

from django_rich.management import RichCommand


class Command(RichCommand):
    def handle(self, *args, **options):
        self.console.print("[bold red]Alert![/bold red]")

You can customize the construction of the Rich console by overriding the make_rich_console class attribute. This should be a callable that will construct a Console, such as a functools.partial. For example, to disable Rich’s default console markup and highlighting:

from functools import partial

from django_rich.management import RichCommand
from rich.console import Console


class Command(RichCommand):
    make_rich_console = partial(Console, markup=False, highlight=False)

    def handle(self, *args, **options):
        ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-rich-1.0.0.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

django_rich-1.0.0-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page