Django – Create custom django-admin command

We could manage our Django project by executing some commands which could be invoked through the For example:

# Sync database
python syncdb

# Start the webserver
python runserver


Not only this built-in commands, we can write our own command too.

1. Create a new Django project and in this example i called it custom_command. (Django 1.6.5) startproject custom_command


2. Move to the project directory and create a new app.

# Move to the project directory
cd custom_command

# Create a new app and give a proper name, in this example scheduler.
python startapp scheduler


3. Move to the scheduler app folder and create some files as highlighted below. The are just empty files.

  + custom_command
  - scheduler
    - management
      - commands


4. Edit the

from import BaseCommand

class Command(BaseCommand):
  args = 'Arguments is not needed'
  help = 'Django admin custom command poc.'

  def handle(self, *args, **options):
    self.stdout.write("Hello World")


5. Include the scheduler app in custom_command/

# Application definition



6. Move to the project root and generate the db.sqlite3.

python syncdb


7. Your hello_world command is ready! You could check the help message by:

python help hello_world


8. Run the hello_world command.

python hello_world


The custom command could also take input parameters as well as different options. For more details, please refer to the official documentation below.

Done =)

Reference: Django 1.6 – Writing custom django-admin commands


4 thoughts on “Django – Create custom django-admin command”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s