Jinja 在扩展布局模板时不渲染任何东西

Jinja doesn't render anything when extending layout template

我试图在页面上显示数据,但该页面完全是空的。我知道数据库中有数据,我知道 query_db 函数 returns 的正确结果,但我无法弄清楚为什么 Jinja 没有呈现数据。是什么导致了这个问题?

@app.route('/toto')
def toto():
    entries = query_db("select col1,col2 from toto where col1 = 'grand test'")
    return render_template('show_results.html', entries = entries)    

show_results.html:

{% extends "layout.html" %}
{% block body %}
  <ul class=entries>
    {% for entry in entries %}
    <li><h2>{{ entry }}</h2>
    <br>
    {% else %}
    <li><em>No entry here</em>
    {% endfor %}
  </ul>
{% endblock %}  

layout.html:

<html>
  <head>
    {% if title %}
    <title>{{ title }} - microblog</title>
    {% else %}
    <title>microblog</title>
    {% endif %}
  </head>
  <body>
    <div>Microblog: <a href="/index">Home</a></div>
    <hr>
    {% block content %}{% endblock %}
  </body>
</html>

Jinja 不允许子模板输出任何不在父模板块中的内容。 (换句话说,块名称必须匹配。)将子模板中的 block body 更改为 block content 或将 layout.html 中的 content 块重命名为 body 和事情会成功的。