【发布时间】:2015-10-15 07:14:54
【问题描述】:
我正在尝试在页面上显示数据,但页面完全是空的。我知道数据库中有数据,并且我知道 query_db 函数返回正确的结果,但我不知道为什么 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>
【问题讨论】:
-
layout.html 中是否有一个名为
body的块? -
嗨@SeanVieira,不。让我把我拥有的东西放在我的
layout.html -
不确定谁喜欢我的问题,但谢谢! 501分!
标签: python sqlite flask jinja2