0π
Turns out there was a subtle problem with my settings.py
splitting method. For anyone coming here from Google, I was following deploydjango.comβs and strategy on splitting settings.py
, however ROOT_DIR
was being defined in terms of the project, i.e. the following structure
$ tree -L 2
.
βββ static
βββ apps
βββ project
βββ __init__.py
βββ settings
βΒ Β βββ __init__.py
βΒ Β βββ base.py
βΒ Β βββ dev.py
βΒ Β βββ prod.py
βββ urls.py
βββ wsgi.py
with the following setting
STATICFILES_DIRS = (
ABS_PATH('apps', 'example_app', 'static'),
)
would result in ROOT_DIR
being set to project/
. And since ABS_PATH
function defines paths based on ROOT_DIR
, the apps/
folder is not visible (it should be preceded with '..'
).
The solution is of course to move apps/
folder inside the project/
folder, which makes sense. I.e. the correct structure is as follows:
$ tree -L 2
.
βββ static
βββ project_name
βββ __init__.py
βββ apps # <-- apps moved here
βΒ Β βββ example_app
βββ settings
βΒ Β βββ __init__.py
βΒ Β βββ base.py
βΒ Β βββ dev.py
βΒ Β βββ prod.py
βββ urls.py
βββ wsgi.py
I realised this problem is very tied to the way I was doing things, however since this structure can be seen by some people as βbest practiceβ (although some disagree), I hope this helps someone!
1π
Check if you have all settings set like that in your settings.py
.
I suppose that your static files are under static
dir in your project root folder.
import os
import sys
STATIC_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static/')
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
INSTALLED_APPS = (
# default apps
'django.contrib.staticfiles',
# etc
)
STATICFILES_DIRS = ()
nginx config:
location /static {
alias /path_to_your_project/static;
access_log off;
expires max;
}