我有一个flask应用程序,该应用程序从表单中获取数据并将其保存到使用SQLAlchemy构建的表中。我正在构建一个仪表板,该仪表板将显示一些信息摘要,例如表中的总条目。我运行了下面的代码,没有错误,但是在html中使用Jinja的位置没有任何显示。
views.py
#equipment home page
@equipment_blueprint.route('/', methods=['GET','POST'])
def equipment_home():
#total equipment card
total_equipment = db.session.query(EquipmentInfo).count()
return render_template('equipment_base.html')
total_equipment变量是我要用来对EquipmentInfo表中的条目进行计数的变量。
html
<!-- first bootstrap card -->
<div class="card text-white bg-dark mb-3" style="max-width: 18rem;">
<div class="card-header">Header</div>
<div class="card-body">
<h5 class="card-title">Dark card title {{ total_equipment }} </h5>
<p class="card-text">Some quick example text to build on the card title
and make up the bulk of the card's content.</p>
</div>
</div>
我尝试将{{total_equipment}}插入html。还有另一种可行的方法吗?我只是将其输入标题以进行测试,以查看其是否有效。
您需要向提供模板变量的名称和值render_template
,如下所示:
return render_template('equipment_base.html', total_equipment=total_equipment)
请参阅此处的文档。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句