Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Invalid block tag: 'static', expected 'endif'

I have a form wherein I'm trying to insert a static image file in between an if-else loop in HTML. Here's the source code of the template:

<!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>

However, this is the error that I'm encountering:

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

How are static images inserted in between if-else loop in templates in Django?

like image 654
Manas Chaturvedi Avatar asked Jun 29 '15 14:06

Manas Chaturvedi


1 Answers

I believe you need to add

{% load staticfiles %} 

at the top of your template.

like image 51
Chris Hawkes Avatar answered Oct 01 '22 23:10

Chris Hawkes