djangodjango-admin

Django: get current manage.py command


I want to know how I can Get current manage.py command from within the code.

For example, when I run syncdb in the shell, I want to get this command name.

How can I do it?


Solution

  • Manage.py is just a python script: if you want to get the command passed to it in a script, it can be found in sys.argv[1]. Subsequent commands are further down the list: sys.argv[0] contains the name of the file executed (manage.py in your example); sys.argv[1:] has all parameters passed to the executed file.