Django: ValueError: Missing staticfiles manifest entry for 'jquery.twbsPaginationAlt.min.js'

816 Views Asked by At

Before marking as duplicate, note that I've checked all the similar questions that have been asked and it has not fixed my problem. I've deployed my Django App on Heroku in in one template where I reference a min.js file, it throws this error in question.

My basic directory structure is this:

myapp
    mysite
    dictionary
    static
        jquery.twbsPaginationAlt.min.js
    staticfiles

settings.py:

STATIC_URL = '/static/'
# STATIC_ROOT = [os.path.join(BASE_DIR, 'staticfiles'), os.path.join(BASE_DIR, 'static/fonts')]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
if DEBUG:
    STATICFILES_DIRS = [os.path.join(BASE_DIR, 'mysite/static'), os.path.join(BASE_DIR, 'static/')]

import django_heroku
# handles staticfiles, database url, and secret key, can be overwritten as needed
django_heroku.settings(locals(), secret_key=False, logging=False)

So originally if STATICFILES_DIRS had any value, I would get an error of FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_6f3eb879/mysite/static' when running collectstatic on heroku. However, if it is not set, than the fonts I have in my dev environment do not load in properly (I also have fonts inside the base level static folder).

This is how I reference the js file in my problem template, it works fine on dev:

    <script src='{% static 'jquery.twbsPaginationAlt.min.js' %}'></script>

For convenience, here is what django-heroku does in terms of staticfiles:

        logger.info('Applying Heroku Staticfiles configuration to Django settings.')

        config['STATIC_ROOT'] = os.path.join(config['BASE_DIR'], 'staticfiles')
        config['STATIC_URL'] = '/static/'

        # Ensure STATIC_ROOT exists.
        os.makedirs(config['STATIC_ROOT'], exist_ok=True)

        # Insert Whitenoise Middleware.
        try:
            config['MIDDLEWARE_CLASSES'] = tuple(['whitenoise.middleware.WhiteNoiseMiddleware'] + list(config['MIDDLEWARE_CLASSES']))
        except KeyError:
            config['MIDDLEWARE'] = tuple(['whitenoise.middleware.WhiteNoiseMiddleware'] + list(config['MIDDLEWARE']))

        # Enable GZip.
        config['STATICFILES_STORAGE'] = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

(from https://github.com/heroku/django-heroku/blob/master/django_heroku/core.py)

EDIT: In order to fix this I had to stop using django heroku, change my STATICFILES_STORAGE variable to whitenoise.storage.CompressedStaticFilesStorage , and reorganize where I kept some of my static files by checking the logs to see what path the GET requests were going to. It seems whitenoise is pretty imperfect based off the other stackoverflow posts I've seen, it consistently misses 'static/' files in the root directory. Additionally since Django relies a lot on the 'static' keyword in templates, and this is not available in .css files, the only way to resolve getting static files into a css file (for fonts for example), is trial and error of testing different paths.

1

There are 1 best solutions below

2
On

This line looks very odd to me and may be the source of the problem:

if DEBUG:
    STATICFILES_DIRS = [os.path.join(BASE_DIR, 'mysite/static'), os.path.join(BASE_DIR, 'static/')]

Why are you only defining your STATICFILES_DIRS in debug mode? You'll need those defined in production too.