Update: looks like this is being cause by the django-heroku package and specifically the inherited whitenoise package, which in docs says your supposed to put
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
at the end of settings file, which I never did but it still enforces root being 'staticfiles' folder instead of assets folder
Original Post:
When I run python manage.py collectstatic it saves to a folder called staticfiles
I must have done something to make this happen, but I've searched for staticfiles and found no reference to it except 'django.contrib.staticfiles'.
Here is my settings.py:
INSTALLED_APPS = [
#some apps
'django.contrib.staticfiles',
#some more apps
'tz_detect',
]
# some more code
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
VENV_PATH = os.path.dirname(BASE_DIR)
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(VENV_PATH, 'media_root')
Expected outcome was for when python manage.py collectstatic is run, that an assets folder would be created, but this never happens.
The staticfiles folder in addition to files from static folder also contains a tz_detect folder (from static assets from 3rd party package), an admin folder, and a staticfiles.json
middleware section of settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
# some more middleware
'tz_detect.middleware.TimezoneMiddleware',
]
It appears that it isn't possible to change the name of your STATIC_ROOT
using django_heroku
, without monkey patching the package.
The line django_heroku.settings(locals())
takes all the local variables (ie STATIC_ROOT
) and passes them into the settings
function found at django_heroku/core.py
.
If you take a look at line 89:
config['STATIC_ROOT'] = os.path.join(config['BASE_DIR'], 'staticfiles')
You will see that whatever value you set for STATIC_ROOT
, the package will override it with staticfiles
.
Note that the following may have unintended consequences, and you shouldn't do them.
Here are 2 monkey patch solutions:
STATIC_ROOT
after you call django_heroku.settings(locals())
:STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
django_heroku/core.py line 89:
to the following:if 'STATIC_ROOT' not in config:
config['STATIC_ROOT'] = os.path.join(config['BASE_DIR'], 'staticfiles')
this will prevent djano_heroku
from overriding the STATIC_ROOT
if you have already defined it.
Again, I don't recommend doing this because there might a good reason that Heroku forces you to use the name staticfiles
, and this might cause your server to break, or worse, parts of your server might silently fail (which means debugging will be a nightmare).