Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use django-compress with Heroku

I have a Django 1.9.6 site deployed to Heroku. When DEBUG=False I was getting a server error (500). The logs contained no useful information, so I tried running it with DEBUG=True. Now it works fine. I think the issue may be tied to my scss file processing, which really confuses me and I was struggling with. I recently--among other things--added COMPRESS_OFFLINE = True to my settings files, and commenting that out seems to alleviate the problem (although then my scss files don't work).

Some of my static settings.py. Let me know if you need more--so much of this is a mystery to me. I was trying to follow this as best as I could.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
    STATICFILES_FINDERS = (
        'django.contrib.staticfiles.finders.FileSystemFinder',
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
        # other finders..
        'compressor.finders.CompressorFinder',
    )

    STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

    MEDIA_URL = "/media/"
    MEDIA_ROOT = os.path.join(BASE_DIR, "media/")

in urls.py:

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += [
    url(r'^media/(?P<path>.*)$', serve, {
        'document_root': settings.MEDIA_ROOT
    }),
]

urlpatterns += staticfiles_urlpatterns()

EDIT:

I've gotten logging to work, and I've confirmed that it's a compress error. I'm getting the error message:

Internal Server Error: /

OfflineGenerationError at /
You have offline compression enabled but key "171c3b7763dbc51a465d996f7d920cf5" is missing from offline manifest. You may need to run "python manage.py compress".

which is the same thing I've gotten locally, except running the suggested command solved it. Running heroku run python manage.py compress doesn't have an effect (no errors running it, though)

like image 828
thumbtackthief Avatar asked Feb 16 '17 00:02

thumbtackthief


1 Answers

The manifest generated by compress was stored in my .gitignore and therefore the one on production was stale. Adding it to the git repository fixed everything.

like image 148
thumbtackthief Avatar answered Sep 25 '22 19:09

thumbtackthief