需要将 db 里的数据输出到网页,不知道为什么一直不对 下面是部分源码 ``` books = get_db() cur = books.execute('select * from BOOKS') id = [] for row in cur: id.append(row[0]) ID = id return render_template("index.html",ID=ID) ``` ### 函数 ``` DATABASE = 'books.db' def init_db(): with closing(connect_db()) as db: with app.open_resource('schema.sql', mode='r') as f: db.cursor().executescript(f.read()) db.commit()
def connect_db(): return sqlite3.connect(DATABASE) def get_db(): db = getattr(g, '_database', None) if db is None: db = g._database = connect_db() return db ``` ### 模板 ``` {% for i in ID %} <div>{{i}}</div> {% endfor %} ``` **确定 books.db 里有数据,但结果什么都不显示**