Reputation: 61
I am trying to start Django on Heroku. I looked around Stack Overflow, I tried different things, but I cannot figure it out. It looks similar to all the questions related to staticfiles problem on Django, unfortunately I don't know where the problem is. My project runs just fine with DEBUG = True
, but when I change it to False, I get following traceback:
2020-11-09T13:13:42.801384+00:00 app[web.1]: Missing staticfiles manifest entry for 'order/css/open-iconic-bootstrap.min.css'
It happens on all of my apps that require staticfiles. I tried to find manifest.json, but it does not exist. So I think this is the issue.
Here are my relevant settings:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
#more ...
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
django_heroku.settings(locals())
Thanks for looking into this!
Upvotes: 2
Views: 1507
Reputation: 5512
@keome in the comments already gave you the first steps in debugging this issue so I won't repeat that here.
Notwithstanding the issues they raised (which should be looked at first), I think the key issue is that your whitenoise configuration isn't set up to generate a manifest. You probably want:
# Serve compressed and manifested static files
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
The reason your current configuration would work with DEBUG=1
is that in debug mode, django will fall back to serve static files itself (neither secure nor efficient).
Second, make sure that you run collectstatic
with the same storage configuration as you're running the server - I cant see what settings files you have, but it seems like you've collected static without a manifesting strategy, but you're trying to serve it with a manifesting strategy (and hence django is confused by why there isn't a manifest).
Incidentally, whitenoise by default creates a staticfiles.json
file, not a manifest.json
file, and it's served as a static file. So if your STATIC_URL = "/static/"
then you can find the manifest at <your-domain>/static/staticfiles.json
.
The reason the manifest of staticfiles isn't actually called manifest.json
is because that'd conflict with the usual name of the manifest.json
served as part of a Progressive Web App (spec here), which is kind of similar (in that it can serve as an instruction to the browser of where to find certain files) but not the same.
Upvotes: 2