Django management command cannot see arguments? -


since upgrading django 1.8, there's strange bug in django management command.

i run follows:

python manage.py my_command $db_name $db_user $db_pass 

and collect arguments follows:

class command(basecommand):  def handle(self, *args, **options):     print args     db_name = args[0]     db_user = args[1]     db_pass = args[2]     self.conn = psycopg2.connect(database=db_name, user=db_user,                                  password=db_pass) 

previously worked fine, see error:

usage: manage.py my_command [-h] [--version] [-v {0,1,2,3}]                                              [--settings settings]                                              [--pythonpath pythonpath]                                              [--traceback] [--no-color] manage.py my_command: error: unrecognized arguments: test test test 

it's not getting far print args statement.

if run without arguments, errors on args[0] line, unsurprisingly.

am using args wrong here? or else going on?

it's change in django 1.8. detailed here:

management commands accept positional arguments¶

if have written custom management command accepts positional arguments , didn’t specify args command variable, might error error: unrecognized arguments: ..., variable parsing based on argparse doesn’t implicitly accept positional arguments. can make command backwards compatible setting args class variable. however, if don’t have keep compatibility older django versions, it’s better implement new add_arguments() method described in writing custom django-admin commands.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -