Question

I wanted to enabling versioning to some of my javascript and css files as I was getting caching problems when working on the site. I read about CachedStaticFilesStorage in Django 1.6 and it seemed perfect. I modified my settings.py to the following settings:

STATIC_ROOT = 'staticfiles'

STATIC_URL = ''

# Additional locations of static files
STATICFILES_DIRS = (
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'

As a test I then rewrote the most problematic of the css tags to see if it would start hashing the file path. I instead got a 500 error whenever I try and load the page.

Any ideas where I went wrong? Is there an additional step I missed?

The entry in the template:

{% block cssfiles %}
{% load static%}
<link href="{% static "/static/css/mapmaker.css" %}" media="screen">
{% endblock %}
Was it helpful?

Solution

Very tricky... If you read the docs carefully, you will learn:

... use the staticfiles static template tag to refer to your static files in your templates ...

So instead of:

{% load static %}

Use

{% load staticfiles %}

OTHER TIPS

This is fixed in Django 1.10, as explained in the documentation:

In older versions, you also had to use {% load static from staticfiles %} in your template. The static template tag ({% load static %}) now uses django.contrib.staticfiles if it’s installed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top