I have a Django project with "django.contrib.staticfiles" in INSTALLED_APPS. Therefore, I can run ./manage.py collectstatic. But I need to use call_command.
Running python -c 'from django.core.management import call_command; call_command("collectstatic")' results in django.core.management.base.CommandError: Unknown command: 'collectstatic'
What am I doing wrong? Shouldn't the 2 commands be absolutely identical? Obviously, environments, paths, etc are correct in both cases. I am running both commands from the same shell in a docker container.
DJANGO_SETTINGS_MODULEenvironment variable set? Also I see you haven't calleddjango.setup()DJANGO_SETTINGS_MODULE='myproj.settings' python -m 'django' collectstatic?./manage.py collectstaticwould not work either if it wasn't?DJANGO_SETTINGS_MODULEenvironment variable or not. You should set it if you haven't (manage.pyhas a line that does this usually). Django uses that to find the settings to be used (And hence discovers the apps to be installed). You should also calldjango.setup()for the same purpose.