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}



-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/cb536a08-2ebf-4041-89d6-5e54aca7aef0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to