【发布时间】:2012-03-31 07:11:54
【问题描述】:
我是SQLite初学者,遇到了一些麻烦,希望能找到可以帮助的人。
我正在尝试从数据库中读取一些数据,将其放入 python 中的变量中,然后将其打印到 HTML 页面上。
数据库中的表名为“Status”,它包含“stamp”和“messages”两列。 "stamp 是一个包含时间戳的 INT,而 "messages" 包含一个 TEXT。
@cherrypy.expose
def comment(self, ID = None):
con = lite.connect('static/database/Status.db')
output = ""
with con:
cur = con.cursor()
cur.execute("SELECT * FROM Status WHERE stamp = ?", (ID,))
temp = cur.fetchone()
output = temp[0]
comments = self.readComments(ID)
page = get_file(staticfolder+"/html/commentPage.html")
page = page.replace("$Status", output)
我得到的错误是:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/cherrypy/_cprequest.py", line 606, in respond
cherrypy.response.body = self.handler()
File "/usr/lib/pymodules/python2.7/cherrypy/_cpdispatch.py", line 25, in __call__
return self.callable(*self.args, **self.kwargs)
File "proj1base.py", line 184, in comment
page = page.replace("$Status", output)
TypeError: expected a character buffer object
我想知道是否有人可以帮助我澄清什么是字符缓冲区对象,以及如何使用它来使我的代码正常工作?
【问题讨论】:
标签: python html database sqlite