从视图传递到模板的列表在模板中为空

时间:2015-08-03 02:43:31

标签: python flask sqlalchemy jinja2

我正在尝试编写一个从数据库中呈现团队名称列表的视图。我获取团队并将它们传递给模板,但模板呈现为空并且没有错误。为什么列表为空?

@app.route('/')
@app.route('/teams/')
def showTeams():
    #return "All teams"
    team = session.query(Team).all()
    return render_template('teams.html', Team = team)
<html>
    <body>
        <h1>NHL Teams</h1>
            {% for i in team %}
            <a href="#">
                <h2>{{ i.team_name }}</h2> 
            </a>
                <a href = '#'>Edit</a> 
                <a href = '#'>Delete</a>
            <!--  {{ url_for('editTeam', team=i.tid) }}   {{ url_for('deleteTeam', team=i.tid) }}-->
        </br>
            {% endfor %}
    </body>
</html>

1 个答案:

答案 0 :(得分:1)

return render_template('templates/newTeam.html', Team = team)中,您使用大写T编写第一个团队,但在模板中您不会。