I've always used the STATIC_URL context processor variable in templates and didn't have trouble with it up until a few days ago when a customer required to use the STATICFILES_STORAGE.
I then realized I would need to change all the {{STATIC_URL}} template references to use a {% static %} tag via {% load static from staticfiles %}, which just seemed overwhelming, so I just tweaked django.template.context_processors.static to make it staticfiles aware.
Given the prevelance of templates that use {{STATIC_URL}} and now the possibility of changing storage, I thought I'd suggest this as a possible new fix/feature. Here's another post which addreses the same problem
http://staticfiles.productiondjango.com/blog/stop-using-static-url-in-templates/ but simply says to use {% load static from staticfiles %} and never use {{STATIC_URL}}. But given the wide use of {{STATIC_URL}} this may be an easy and worthwhile fix instead of asking users to change template references.
What do you think ?
Current django.template.context_processors.static is pretty basic:
def static(request):
"""
Adds static-related context variables to the context.
"""
return {'STATIC_URL': settings.STATIC_URL}
It would change to something like
def static(request):
"""
Adds static-related context variables to the context.
"""
if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
from django.contrib.staticfiles.storage import staticfiles_storage
return {'STATIC_URL':staticfiles_storage.url }
else:
return {'STATIC_URL': settings.STATIC_URL}