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.7 to 3.10 supported.

Django 2.2 to 4.0 supported.


Want to work smarter and faster? Check out my book Boost Your Django DX which covers many ways to improve your development experience. I wrote django-rich whilst working on the book!


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. 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.

You can use self.console like so:

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 Console by overriding the make_rich_console class attribute. This should be a callable that returns a Console, such as a functools.partial. For example, to disable the default-on markup and highlighting flags:

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.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_rich-1.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file django-rich-1.1.0.tar.gz.

File metadata

  • Download URL: django-rich-1.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for django-rich-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0e23dfed973faab4db8e6201067b007db03cce6f368e6bef9eaf906e379c627f
MD5 1d6e30f43fe7873fe42a7aae2aa09fbf
BLAKE2b-256 860f8311a4e52730b1d4644c6d06571989ee094eed955c08f967b94849f6f319

See more details on using hashes here.

File details

Details for the file django_rich-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_rich-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for django_rich-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12a3873a1fa9ff29345f650fbd1b973a781cc73fdf2d549b678fff7c6578c5d3
MD5 1c0eb2f543171d60c9a6f44599253c44
BLAKE2b-256 f347b5e1549beb4e9f94331e0e9e5cbfd8e725c9913a7efe6fb744badd27567e

See more details on using hashes here.

Supported by

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