I want to make a program that it can create a HTML page. It should be able to make a table (with data provided) using the HTML by the program itself.
This code also uses wsgi so when the program runs you will need to type the localhost on a browser.
But there are some errors in this code and I am not exactly sure what is wrong with them. Any suggestions?
[code]def table(headings, data):
tableString = """<html>
<title>This is the Title</title>
<table>
<tr>
""" + getHeaders(headings) + """
</tr>
""" + getRows(data) + """
</table>
</html>
"""
def getHeaders(headings):
headers = ""
count = 0
while count <len(headings):
head = headings[count]
headers += "<th>%</th>\n" % head
count = count +1
def getRows(data):
rowentry = " "
for row in data:
#rowentry += "<tr>%s..."
rowitem = ""
count = 0
while count <len(row):
cell = row[count]
rowitem += "<tr>%s</tr>" % cell
count = count + 1
rowentry += "<tr>%s</tr>" % (rowitem)
return rowentry
from wsgiref import simple_server
def application(headers, start_response):
headers = [('content-type', 'text/html')]
start_response('200 OK', headers)
tablehead = ['First Name', 'Last Name', 'Age'}
tabledata = [['Steve', 'Cassidy', '21'],
['John', 'Smith', '22'],
['Mary', 'Margaret', '23']],
print table(tablehead, tabledata)
return [table(tablehead, tabledata)]
if name = 'main':
server = simple_server.make_server('localhost', 8080, application)
print 'Running server...'[/code]