Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call collectstatic management command programatically using call_command with options like -l or --noinput

Tags:

python

django

I am trying to call collectstatic command usig call_command but when I want to use option like -l or --noinput

django.core.management.call_command('collectstatic','--noinput')

Its giving me an error

CommandError: Command doesn't accept any arguments

Please let me know how can I call this, how to pass this options.

Thanks in Advance

like image 632
Ranzit Avatar asked Apr 28 '15 06:04

Ranzit


People also ask

How do I run manage PY in Runserver?

1) python manage.py runserver It means to run a emulated server on your local computer. So, after running it, you can go to localhost:8000 or 127.0. 0.1:8000. Requirements: You must run this in the ROOT of your django project where manage.py lives.


2 Answers

This is covered in Django's official Documentation: (https://docs.djangoproject.com/en/1.8/ref/django-admin/#running-management-commands-from-your-code) the proper way to call the command should be:

from django.core.management import call_command

call_command('collectstatic', verbosity=0, interactive=False)
like image 74
petkostas Avatar answered Sep 22 '22 12:09

petkostas


Check the source code of collectstatic.py

Inside add_arguments function, the dest keyword is what you are looking for. You then pass that value to call_command() as argument.

EDIT: However, looking more carefully, I see that, -l, -c, -n have no dest. Thus it's unclear know how to pass those arguments :(

like image 33
stelios Avatar answered Sep 21 '22 12:09

stelios