jinja2.exceptions.TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'endblock'

jinja2.exceptions.TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'endblock'

我在 for 语句中删除了一个 if 语句,现在我有一个明显的内锁错误...我检查了这里的其他一些帖子,我认为我的缩进是正确的,我没有任何额外的间距。 ..我不确定它可能是什么...

{% extends 'layout.html' %}

{% block content %}
<h1>Users <small>Admin {{session.username}}</small></h1>
<a class="btn btn-success" href="/add_user"> Add User</a>
<hr />
<table class="table users">
    <tr>
        <th>ID</th>
        <th>Roles</th>
        <th>Email</th>
        <th>Username</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th></th>
        <th></th>
    </tr>
    {% for user in users %}
    <tr>
        <td>{{user.id}}</td>
        <td>{{user.username}}</td>
        <td>{{user.first_name}}</td>
        <td>{{user.last_name}}</td>
        <td><a href="edit_user/{{user.id}}" class="btn btn-default pull-right">EDIT</a></td>
        <td>
            <form action="{{url_for('edit_user', id=user.id)}}" method="post">
                <input type="hidden" name="_method" value="post" />
                <input type="submit" value="DELETE" class="btn btn-danger" />
            </form>
        </td>
    </tr>
    {% endfor %}
</table>
{% endblock %}

我没有发现您的代码有任何问题,但我猜您需要禁用缓存并强制重新加载模板:

app.config['TEMPLATES_AUTO_RELOAD'] = True

参考https://flask.palletsprojects.com/en/1.1.x/api/?highlight=templates_auto_reload#flask.Flask.templates_auto_reload

让我知道它是否有效。