[Django]-Django admin.py Unknown command: 'collectstatic'

45👍

I had a similar error message, but despite my suspicions, it had nothing to do with the Django update. If you have an error in settings (I had an empty SECRET_KEY value), then “django” will be the only app that gets loaded. I found the root of the problem by running python manage.py shell and that quickly told me what’s wrong with the settings.

👤jbasko

25👍

For those coming here from google, I resolved it through adding

'django.contrib.staticfiles',

to INSTALLED_APPS

9👍

If you change name or destanation of your settings.py file, you need to invoke your manage.py with key –settings.

2👍

I recently came across this issue.

First, in your question, INSTALLED_APPS is missing a closing bracket… so check that isn’t the problem!

For me, the missing management commands was due to the MEDIA_URL setting missing a trailing slash. For some reason, this caused all commands, except the base django commands, to be missing when I used ./manage.py --help

The way I discovered this was to run a base command, which informed me of the problem with my settings.py file.

1👍

Maybe it is caused by “TEMPLATE_CONTEXT_PROCESSORS” . The official documentation says:

Be careful when you override settings, especially when the default value is a non-empty tuple or dictionary, such as MIDDLEWARE_CLASSES and TEMPLATE_CONTEXT_PROCESSORS. Make sure you keep the components required by the features of Django you wish to use.

And I checked the default value at Django setting documentation It seems that you missed an options:

"django.core.context_processors.tz"

The whole list of default values are:

> ("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages")

And in my django project’s setting file, I didn’t find this value. SO I think maybe you do not need to override this value.

1👍

Make sure 'django.contrib.staticfiles' is in INSTALLED_APPS.

1👍

Most probably this is caused by due to the configuration in settings.py file
you can run perform Django’s check to figure out the exact issue

python manage.py check --settings=test_settings

you can additionally specify the settings file to check against.

👤Aarif

0👍

give a closing bracket to your Installed apps and change the MEDIA_URL='/media' to
MEDIA_URL='/media/' see if it works

0👍

I had the same problem in Django 1.10.3. In my case, I forgot to register one app in my settings.py. Adding the name of the app in INSTALLED_APPS solves the problem.

0👍

This might happen when environment variable DJANGO_SETTINGS_MODULE is missing.

Run export DJANGO_SETTINGS_MODULE=<your settings module> and see if it fix the problem.

👤Haojin

0👍

I had same issue in Django 2.2.7 and found that command here:

(venv) lead@ip-XXX-XX-XX-XXX:~/Develop/dev_1_2/myproject$ python manage.py help

Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

...

[django]
    check
    compilemessages
...
    startapp
    startproject
    test
    testserver

[sessions]
    clearsessions

[staticfiles]
    collectstatic
    findstatic
    runserver

because you can run this as:

python manage.py collectstatic

0👍

  1. Make sure settings.py file is present in the default location.
    Or "python manage.py" knows the new settings.py file location.
    For eg.
python manage.py collectstatic --settings=projectname.settings
  1. Make sure STATIC_ROOT is present in the settings.py file
    For eg.
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

0👍

For me, this was the result of using this in my settings:

import project.settings.base

instead of

from project.settings.base import *
👤damd

Leave a comment