pythondjangoproduction-environmentdjango-staticfileswhitenoise

Django doesn't load static files ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)


is my first app in Django and I am trying to prepare my Django (2.0) application for production, but I am unable to make the static files load properly using WhiteNoise

I keep having all the time the next error in my log

ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
ValueError: Missing staticfiles manifest entry for 'css/inicio.css'
[02/Jun/2018 14:40:37] ERROR [django.server:124] "GET /participation/prueba HTTP/1.1" 500 27

I have the following settings.py

...
DEBUG=False
DJANGO_APPS = ['django.contrib.admin',
                'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.sessions',
                'django.contrib.messages',
                #Delete for development whitenoise.runserver_nostatic
                'whitenoise.runserver_nostatic',
                'django.contrib.staticfiles',
                'django.contrib.sites'
               ]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
...
STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')

STATICFILES_DIRS = (
    (os.path.join(BASE_DIR, 'static')),
)

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

I have all my static files in a folder call static at root level, when I run manage.py collectstatic I get generate all the static files in the staticfiles dir, but somehow still I don't manage to make it run.

I try to isolate the problem and I am using the following template

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    {% load static %}
    <link rel="stylesheet" href="{% static "css/inicio.css" %}">
</head>
<body>


{% for categoria in categoria_list %}
    <p>
        {{ categoria.titulo }}
    </p>
{% endfor %}


</body>
</html>

I have try already to change the path of href to

{% static "/css/inicio.css" %}
{% static "static/css/inicio.css" %}

but none of them have make it load

Also I tried with and without 'whitenoise.runserver_nostatic' loaded in Django Apps and I keep having the same results.

Anyone knows what i am doing wrong ?

Thanks in advance.


Solution

  • Try removing this line,

    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
    

    Source: https://stackoverflow.com/a/32347324/2596187