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