I am learning cherrypy framework for my python development.I created a database,inserted some data and now I want to retrieve it and show it in the browser.Data is created in the sqlite database but when displaying the data it simply shows for loop instead of printing the data in the browser.
import sqlite3
import cherrypy
class simple_db(object):
@cherrypy.expose
def index(self):
db = sqlite3.connect('picnic.db')
c = db.cursor()
c.execute("SELECT item,quant FROM picnic")
data = c.fetchone()
c.close()
output = open("data.html")
return output
if __name__ == '__main__':
cherrypy.config.update("app.conf")
cherrypy.quickstart(simple_db())
My html file,
<h1>Things to bring to our picnic</h1>
<head>
<style>
table {
border-collapse: collapse;
}
</style>
</head>
<table border=1>
<tr><th>Item</th><th>Quantity</th></tr>
% for row in data:
<tr>
% for col in row:
<td>{{col}}</td>
% endfor
</tr>
% endfor