【问题标题】:Django: Invalid block tag: 'static', expected 'endif'Django:无效的块标签:'static',预期的'endif'
【发布时间】:2015-09-16 01:07:42
【问题描述】:

我有一个表单,我试图在 HTML 中的 if-else 循环之间插入一个静态图像文件。这是模板的源代码:

<!DOCTYPE html>
<html>
    <head>
        <title>Rango</title>
    </head>

    <body>

    <p>
   <ul>
   {% if user and not user.is_anonymous %}
     <li>
       <a>Hello {{ user.get_full_name|default:user.username }}!</a>
     </li>
     <li>
       <a href="{% url 'auth:logout' %}?next={{ request.path }}">Logout</a>
     </li>
   {% else %}
    <li>
       <a href="{% url 'social:begin' 'twitter' %}?next={{ request.path }}"><img src="{% static "images/twitter.png" %}" /></a>
     </li>
   {% endif %}
   </ul>
 </p>
        <form id="evangelized_form" method="post" action="/rango/fillform/">

            {% csrf_token %}
            {% for hidden in form.hidden_fields %}
                {{ hidden }}
            {% endfor %}

            {% for field in form.visible_fields %}
                {{ field.errors }}
                <b>{{ field.help_text }}</b><br>
                {{ field }}<br><br>
            {% endfor %}

            <input type="submit" name="submit" value="Submit" />
        </form>
    </body>

</html>

但是,这是我遇到的错误:

TemplateSyntaxError at /rango/fillform/
Invalid block tag: 'static', expected 'endif'

如何在 Django 模板中的if-else 循环之间插入静态图像?

【问题讨论】:

    标签: python html django python-2.7


    【解决方案1】:

    我相信你需要添加

    {% load staticfiles %} 
    

    在模板的顶部。

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2016-01-26
      • 2015-07-08
      • 2013-06-20
      • 1970-01-01
      • 2012-06-28
      • 2012-05-03
      • 1970-01-01
      • 2014-08-29
      相关资源
      最近更新 更多