开发者

Error with static template block tag in Django 1.3

开发者_Go百科

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜