Home > front end >  flask jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'endif'
flask jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'endif'

Time:12-16

So in Flask I have this template:

{% extends "base.html" %} 

{% block title %} Chatroom mit {{name}}{% endblock %}

{% block content %}
<div >
<div ><img src="static\images\{{prof_pic}}" > </div> <div ><strong>{{name}}</strong></div>
 </div>
 <div >
<div >
{% for key in real_keys %}
<p>
{% if send in key %}
<div >
<button  type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
  {{real_dict[key]}}
</button>
<ul  aria-labelledby="dropdownMenuButton1">
  <li><a  href="#"><form action="/{{user_id}}" method="POST"><input type="submit" name="delete" id="delete{{id_view[key]}}" value="Delete!"><input type="hidden" name="id_identifier" value="{{ id_view[key] }}" id="id{{id_view[key]}}"></form>
    </a></li>
</ul>
</div>
{% elif rec in key %} 
<div > 
    {{real_dict[key]}} 
</div>
{% endif %}
</p>
{% endfor %}
</div>
</div>
<form method="POST" action="/{{user_id}}" >
<input type="text" id="message" name="message"  autocomplete="off">
<input type="submit" value="submit" name="submit" >
</form>
{% endblock %} 

The error seems to occur in line 26: '{% endif %}'.

This is the error:

jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.

real_dict is a dict with one item in it, and real_keys is the key. leng_dict is another working dict. send and rec are defined variables, they shouldn't cause an error.

I am confused, since I'm pretty sure endif is the innermost block, that needs to be closed. Also if I change it to endfor it still throws an error.

Any kind of help is appreciated, thank you very much

CodePudding user response:

I believe this causes the error:

<div > 

So, try removing {% endif %} here.

  • Related