Skip to content
Advertisement

Django Management Command Argument

I need to pass in an integer argument to a base command in Django. For instance, if my code is:

JavaScript

I want to run:

JavaScript

so, it will return 16.

Is there a way I can pass an argument through the terminal to the command I want to run?

Advertisement

Answer

Add this method to your Command class:

JavaScript

You can then use your option in the code, like this:

JavaScript

The benefit of doing it this way is that the help output is automatically generated for manage.py my_command --help

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement