Reputation: 745
I am running a small test project with Django 1.3, Ubuntu 11.10, gunicorn and Nginx, everything in a virtualenv, and now I'm running collectstatic to get my static files into the directory that Nginx serves from.
For simplicity's sake let's say my static directory is something like /home/user/static and my project is at /home/user/project
When I go to /home/user/project I run:
python manage.py collectstatic --noinput
and it correctly copies static files from all the apps I have installed. Unfortunately this also copies the files from Django's admin and I would like to skip that one.
I checked the documentation for collecstatic and there´s an -i (--ignore) parameter that takes a glob-style parameter so I tried different variations of the command, as I´m not sure if the ignore pattern refers to my /home/user/static or to the original app directory.
Here some examples that didn´t work:
python manage.py collectstatic --noinput -i /home/user/static/admin
python manage.py collectstatic --noinput -i /home/user/static/admin/*
python manage.py collectstatic --noinput -i /home/user/static/a*
python manage.py collectstatic --noinput -i /home/alexis/.virtualenvs/django13/*
python manage.py collectstatic --noinput -i /home/user/.virtualenvs/django13/lib/python2.7/site-packages/django/contrib/admin*
I found that if I create a symbolic link from /home/user/static/admin to /home/user/.virtualenvs/django13/lib/python2.7/site-packages/django/contrib/admin/media collectstatic will notice and skip copying those files again but anyway, I´d like to make the --ignore option work as it should.
What am I missing?
Thanks for the help!
Upvotes: 36
Views: 16443
Reputation: 18943
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.
The take-away is:
Upvotes: -1
Reputation: 23582
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.
Upvotes: 12
Reputation: 597
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.
Upvotes: 45