尝试从较新的顶部撤消帖子,但我在Flask中不断收到错误

时间:2018-09-02 18:39:51

标签: python flask

这是我要在Flask应用中运行的代码

    {% extends "bootstrap/base.html" %}
{% block title %}Testing title{% endblock %}


    {% block content %}
<div class="container">
    <h1>Posts</h1>
    <h3>Postings</h3>
        <form action="/" method="post">
            <input hidden placeholder="Name" name="name">
            <input placeholder="Post whatever you want..." name="post" required>
            <button class="btn btn-primary" type="submit" value="Submit">Submit</button>
        </form>
        {% for post in posts reversed %}
        <div>
            {{ 'Anonymous' + ': ' + post[2] }}
        </div>
        {% endfor %}
</div>

{% endblock %}

这是我得到jinja2.exceptions.TemplateSyntaxError的错误:预期标记“语句块结尾”,被“反转”

颠倒的数字会起作用,因为我在网上找到了一些可以做到这一点的例子

1 个答案:

答案 0 :(得分:0)

Jinja2中以相反顺序循环通过列表的正确语法是:

{% for post in posts|reverse %}
    {{ post }}
{% endfor %}