I'm using Django 1.3.1 and the contrib.collectstatic
app to manage my static files.
My project structure is
myproject
- settings.py
- static-media
- urls.py
- media
- manage.py
where static-media
is a folder containing the static files for this project. In my settings.py I have:
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_PATH, "static")+'/'
STATIC_URL = "/static/"
STATICFILES_DIRS = (
os.path.join(PROJECT_PATH, 'static-media'),
)
I'm using admin_tools to change the layout of the admin. However I want to override a specific css file ( theming.css )from admin_tools. So in my static-media folder I put admin_tools/css/theming.css.
When I first run python manage.py collectstatic
, it works as expected by ignoring the default theming.css in admin_tools and using the one I defined in static-media. Unfortunately if i run the command again, it overrides my css and adds the default.
Here's the output for python manage.py findstatic admin_tools/css/theming.css
:
Found 'admin_tools/css/theming.css' here:
/home/paulo/Desktop/Projects/zennetwork/prd/zennetwork/static-media/admin_tools/css/theming.css
/home/paulo/Desktop/Projects/zennetwork/prd/lib/python2.7/site-packages/admin_tools/theming/static/admin_tools/css/theming.css
Any help is appreciated. Thanks.
The Django docs say only:
Duplicate file names are by default resolved in a similar way to how template resolution works: the file that is first found in one of the specified locations will be used. If you're confused, the findstatic command can help show you which files are found.
Based on your output from findstatic
the first one should be your custom style, and should therefore be the one collected. Why it's not doing that is a mystery.
You could always just ignore the other file explicitly. It's a bit of a pain, but it'll guarantee that your style doesn't get overwritten:
python manage.py collectstatic --ignore site-packages/admin_tools/css/theming.css
If you need to ignore other files, as well, you can keep adding --ignore <pattern>
. This is admittedly not a very viable long-term solution, though.