使用Python、flask和SQLAlchemy如何在HTML页面上打印DB查询的结果?

2024-04-25 10:10:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个非常简单的查询(刚从SQLAlchemy开始),我知道它是有效的,因为它在终端中打印,而不是在HTML页面上打印,这就是问题所在。在

具体如下:

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import *
from models import db, Candidate, User, Template
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

some_engine = create_engine('databse_url')
Session = sessionmaker(bind=some_engine)
session = Session()

@application.route("/", methods=['GET', 'POST'])
def index():
    res = session.query(Template).all()
    for temp in res:
            print temp.spark_id
    return render_template('index.html')

在终端中,2个“spark iu id”被打印出来,但是在HTML页面上我什么也没有得到。在

在索引.html第1页:

^{pr2}$

出什么问题了?在


Tags: fromimport终端indexsqlalchemysessionhtmlcreate