Error with static template block tag in Django 1.3

I try to use the static template template tag in one of my templates, but I get an exception that I don't understand.

Here is the template code:

<img src="{{STATIC_URL}}closed.png" alt="Closed message" /> <br/> {% load static %} <img src="{% get_static_prefix %}closed.png" %}" alt="Closed message"/> <br/> <img src="{% static "closed.png" %}" alt="Closed message"/> 

The first two image display instructions work if I comment on the last. When the last one is uncommented, I get an exception:

Invalid block tag: 'static'

The code is based on this section of the django documentation.

+7
source share
3 answers

Are you using a development version? Most likely you are using version 1.3, in which case you should look for this documentation .

+3
source

If someone is at> 1.3 and gets this problem, check your INSTALLED_APPS and make sure that 'django.contrib.staticfiles' present. Your template includes: {% load staticfiles %} , and then use it as such:

 //ensure the your syntax is correct <link rel="shortcut icon" type="image/x-icon" href="{% static "assets/favicon.ico" %}?v=2" /> 

I ran into this problem because I had a syntax error and my django projects docs setup was checked .

+12
source

I had the same problem and the problem turned out to be that I forgot

 {% load staticfiles %} 

Read more about this in the Django documentation here.

+11
source

All Articles