django-planet
Aug. 13, 2024

Django: create sub-commands within a management command

published by Adam Johnson
in blog Adam Johnson
original entry Django: create sub-commands within a management command

argparse, the standard library module that Django uses for parsing command line options, supports sub-commands. These are pretty neat for providing an expansive API without hundreds of individual commands. Here’s an example of using sub-commands in a Django management command:

from django.core.management.base import BaseCommand


class Command …