0

I'm trying to make the Django 'static' tag available in all templates. I've tried this suggestion:

from django.template.loader import add_to_builtins
add_to_builtins('django.contrib.staticfiles') # I've tried each of these
add_to_builtins('django.contrib.staticfiles.templatetags') 
add_to_builtins('django.contrib.staticfiles.templatetags.staticfiles') 

But keep getting the following error message:

django.template.base.InvalidTemplateLibrary: Template library django.contrib.staticfiles does not have a variable named 'register'

What am I doing wrong?

Thanks

Community
  • 1
  • 1
Trent
  • 2,328
  • 3
  • 33
  • 51
  • If I understand the question right, I think we were asking the same thing. Answered here: http://stackoverflow.com/questions/18709803/load-django-static-template-tag-library-globally-without-explicitly-loading-it – phazei Sep 10 '13 at 04:35

2 Answers2

0

You need to add 'django.core.context_processors.static', in your settings.py like this:

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.request',
    'django.contrib.messages.context_processors.messages',
)
Thomas Schwärzl
  • 9,518
  • 6
  • 43
  • 69
  • I just tried that but I am getting an "Invalid block tag: 'static'" error (after removing the explicit 'load static tags' calls in my templates) – Trent Oct 08 '12 at 08:46
  • do I understand it right - you want `{{ STATIC_URL }}` in your templates and are just mixing it up with `static`? – Thomas Schwärzl Oct 08 '12 at 11:07
  • sorry, should have made myself a bit clearer! I want to be able to use the 'static 'tag (new in django 1.4) without having to load the 'static' tag library in each template. See https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#static – Trent Oct 08 '12 at 21:39
  • Oh, ok. Are you sure you've added https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_STORAGE to your `settings` and `collectstatic` everything? Works here out of the box. – Thomas Schwärzl Oct 09 '12 at 05:47
0

Question is answered on SO here

Trent
  • 2,328
  • 3
  • 33
  • 51