如何从 sqlite return 值 web?

How to return value web from sqlite?

这是我的代码。我想在网络上显示这些值。怎么做?

import sqlite3

def application(environ, start_response):

 db = sqlite3.connect('/root/example.db')
 db.row_factory = sqlite3.Row
 cursor = db.cursor()
 cursor.execute('''SELECT id, message,date FROM table''')
 for row in cursor:
  print('{0} : {1}, {2}'.format(row['id'], row['message'], row['date']))
 db.close()

 start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])

建立一个字符串列表return;打印写入 stdout 而不是 returned 到浏览器。

db = sqlite3.connect('/root/example.db')
db.row_factory = sqlite3.Row
cursor = db.cursor()
cursor.execute('''SELECT id, message,date FROM table''')

results = []
for row in cursor:
    results.append('{0} : {1}, {2}'.format(row['id'], row['message'], row['date']))
db.close()


headers = [
    ('Content-Type', 'text/html; charset=utf-8'),
    ('Content-Length', str(sum(len(line) for line in results)))
]

start_response('200 OK', headers)

return results