3
块,我得到Invalid block tag: 'static', expected 'endif'
,当我作出以下模板无法嵌套{%静态%}标签下,如果在Django模板
{% load staticfiles %} <!-- in base.html -->/
<!-- ... -->
{% block content %}
{% if ava_url %}
<div><img src="{{ava_url}}"></div>
{% else %}
<div><img src="{% static 'img/default_ava.png' %}"></div>
{% endif %}
{% endblock %}
我为什么不能if
下窝static
?
使用Django 1.6.7
UPD这是在所有块容器中。可能是原因。然而,当我删除if
{% load staticfiles %} <!-- in base.html -->
<!-- ... -->
{% block content %}
<div><img src="{% static 'img/default_ava.png' %}"></div>
{% endblock %}
我得到Invalid block tag: 'static', expected 'endblock'
UPD解决。在衍生模板中包含{% load staticfiles%}
。对不起,这不是显而易见的,{% load staticfiles%}
首先在基本模板中。答案被发现here
但是我需要进一步解释:为什么{% load staticfiles%}
不能从基本模板工作?
什么是你的Django的版本? – 2015-01-20 21:36:13
django版本1.6.7 – 2015-01-20 21:37:38
您是否将django.contrib.staticfiles添加到已安装的应用程序? – 2015-01-20 21:41:55