Django Management Commands

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Management commands are powerful and flexible scripts that can perform actions on your Django project or the underlying database. In addition to various default commands, it's possible to write your own!

Compared to regular Python scripts, using the management command framework means that some tedious setup work is automatically done for you behind the scenes.

Remarks

Management commands can be called either from:

  • django-admin <command> [options]
  • python -m django <command> [options]
  • python manage.py <command> [options]
  • ./manage.py <command> [options] if manage.py has execution permissions (chmod +x manage.py)

To use management commands with Cron:

*/10 * * * * pythonuser /var/www/dev/env/bin/python /var/www/dev/manage.py <command> [options] > /dev/null


Got any Django Question?