About Pretty Printing to Stdout
In your Django management commands, you can pprint
an object to stdout
by passing stdout._out
as the stream
parameter:
# core/management/commands/pprint_setting.py
from pprint import pprint
from django.core.management.base import BaseCommand
from django.conf import settings
class Command(BaseCommand):
help = "Prints out the requested setting"
def add_arguments(self, parser):
parser.add_argument("setting_name")
def handle(self, *args, **options):
setting_name = options.get("setting_name")
setting_value = getattr(settings, setting_name)
pprint(setting_value, stream=self.stdout._out)
Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2 Python 3
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.