简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM