MarkerDave
MarkerDave

Reputation: 355

Django static files not found Value error

I'm working on a project using cookiecutter django template: https://github.com/pydanny/cookiecutter-django The project is run in docker containers that come with the cookiecutter-django template on ubuntu 16.04LTS.

When trying to get the site to production, it returns the following error on some pages:

the file 'events\css\themes\fontawesome-stars.css' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f830be38ac8>.

folder structure is:

./project/events/static/
└── events
    ├── css
        ├── details.css
        ├── list.css
        └── themes
            ├── fontawesome-stars.css
            └── fontawesome-stars-o.css

No errors are reported during docker build process and after that running collectstatic. Permissions for the files on the server are set to 775.

static config in base.py config:

# STATIC FILE CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(ROOT_DIR('staticfiles'))

# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = '/static/'

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [
    str(APPS_DIR.path('static')),
]

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

In template I'm including the file like this.:

{% load static %}
{% load crispy_forms_tags %}
{% block title %}
{% endblock%}

{% block css %}
{{block.super}}
<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="{% static 'events\css\themes\fontawesome-stars.css' %}">
{% endblock %}

Upvotes: 1

Views: 865

Answers (1)

dethos
dethos

Reputation: 3454

How are you including the static files on your templates? It looks you are specifying the path directly. Instead you should use:

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'events/css/themes/fontawesome-stars.css' %}">

Because in production whitenoise and collectstatic command will add extra content to the file name for versioning, caching and other purposes.

Upvotes: 1

Related Questions