9 Management commands

 

This chapter covers

  • Management commands built into Django
  • Writing your own management commands
  • Passing command-line arguments to management commands
  • Creating unit tests for management commands

Management commands are Python scripts that allow you to control your Django project from the command line. Over two dozen commands are included with Django, and you can also write your own. This chapter covers management commands you haven’t seen so far, along with details on how to build and test custom commands.

9.1 Management commands in practice

You’ve already used a number of management commands throughout this book. You’ve seen how to create a Django project, create a Django app, create a superuser, create and migrate ORM tables, launch a Django-aware REPL, launch your database’s command-line tool, save and load fixtures, and run your unit tests. The common thread here is producing a change in your project without a web interface. A significant percentage of Django commands are about bootstrapping, deploying, testing, and debugging your software.

9.1.1 Built-in management commands

9.1.2 Changing a password

9.1.3 Configuration

9.1.4 Flushing the database

9.1.5 SQL commands

9.2 Writing your own management command

9.3 Handling arguments

9.3.1 Built-in arguments

9.4 Testing, and using STDOUT and STDERR

9.5 Exercises

Summary