I'm trying to use the static template block tag in one of my template but I get an exception 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 two first image display instructions work if I comment out the last one. When the last one is uncommented I get an exception:
Invalid block tag: 'static'
The code is based on this django documentation section.
If someone is on > 1.3 and gets this issue, check your INSTALLED_APPS and make sure that 'django.contrib.staticfiles'
, is present. In your template include: {% 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 verified my setup as per django projects docs.
I had the same problem, and the problem turned out to be that I forgot to
{% load staticfiles %}
More about it at Django Documentation here
Are you using the development version? Most likely, you're using version 1.3, in which case you should be looking at this documentation instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With