Custom Django Management Commands


Django tip:

You can create your own custom Django management commands that you can run with manage.py. For example:

python manage.py your_command

Simply add a Python module to a "management/commands" folder in a Django app.

Example:

your_app/
    __init__.py
    models.py
    management/
        __init__.py
        commands/
            __init__.py
            your_command.py
    tests.py
    views.py

(Django will ignore any module that begins with an underscore.)

Example command:

from django.core.management.base import BaseCommand

class Command(BaseCommand):

    def handle(self, *args, **options):
        self.stdout.write('pong!')