Django: Invalid block tag: 'static', expected 'endif' [duplicate]
Asked Answered
T

2

6

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?

Toothpaste answered 29/6, 2015 at 14:9 Comment(0)
C
14

I believe you need to add

{% load staticfiles %} 

at the top of your template.

Curtis answered 29/6, 2015 at 14:12 Comment(1)
{% load static %}Beehive
B
0

Add {% load static %}

then it worked for me

Beehive answered 6/10 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.