Extensions for using Rich with Django.
Project description
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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_rich-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a3873a1fa9ff29345f650fbd1b973a781cc73fdf2d549b678fff7c6578c5d3 |
|
MD5 | 1c0eb2f543171d60c9a6f44599253c44 |
|
BLAKE2b-256 | f347b5e1549beb4e9f94331e0e9e5cbfd8e725c9913a7efe6fb744badd27567e |