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?
I believe you need to add
{% load staticfiles %}
at the top of your template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With