Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with static template block tag in Django 1.3

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.

like image 916
chmike Avatar asked Aug 08 '11 14:08

chmike


3 Answers

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.

like image 54
radtek Avatar answered Sep 24 '22 21:09

radtek


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

like image 44
CodyBugstein Avatar answered Sep 21 '22 21:09

CodyBugstein


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.

like image 33
Daniel Roseman Avatar answered Sep 20 '22 21:09

Daniel Roseman