[Django]-How to ignore directories when running Django collectstatic?

43đź‘Ť

Don’t write full path of directories. For example usage:

python manage.py collectstatic --noinput -i admin

This command won’t copy the admin/ directory to STATIC_ROOT path.

12đź‘Ť

The Django 2.2 release has finally addressed the very longstanding issue of specifying ignore parameters with path matching, for example

manage.py collectstatic --ignore /vendor/*.js

should then work.

-1đź‘Ť

I have a folder structure like this:

my_project
└─content
| └─static
|   └─content
|     ├─css
|     ├─dist
|     ├─js
|     ├─scss

I want to exclude the scss folder and all files in it.

I document all the things I tried below.

Here are the commands that DON’T work:

"python manage.py collectstatic --no-input --ignore /content/static/content/scss"
"python manage.py collectstatic --no-input --ignore /content/static/content/scss/"
"python manage.py collectstatic --no-input --ignore /content/static/content/scss/*"
"python manage.py collectstatic --no-input --ignore content/static/content/scss"
"python manage.py collectstatic --no-input --ignore content/static/content/scss/"
"python manage.py collectstatic --no-input --ignore content/static/content/scss/*"
"python manage.py collectstatic --no-input --ignore /content/scss"
"python manage.py collectstatic --no-input --ignore /content/scss/"
"python manage.py collectstatic --no-input --ignore /content/scss/*"
"python manage.py collectstatic --no-input --ignore content/scss"
"python manage.py collectstatic --no-input --ignore content/scss/"

Here are the commands that DO work:

"python manage.py collectstatic --no-input --ignore content/scss/*" <- best
"python manage.py collectstatic --no-input --ignore content/scss*"

The absolute key to understanding this is to read this ten times:

You need to find the path from static directories, not project
root.

Source

The take-away is:

  • you don’t need a leading forward slash at the start of the path
  • the path is relative from your static directories

Leave a comment