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>
        """ + getHeaders(headings) + """
    """ + getRows(data) + """

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]

Edited 4 Years Ago by boiishuvo: needed to modify one word

Could you repost with new code markup, which is indention by at least 4 spaces, after empty line, so you could do in your python editor:

ctrl-A, indent, ctrl-C, undo (or close without saving)

and paste it to your post. Or make empty line, paste code, select it by mouse and clic the Code from menu ribbon.

Edited 4 Years Ago by pyTony: spelling, clarification

Start by testing your functions. This is very basic stuff. So in the function "table", print tableString at the end. Also you should be getting a syntax error on this line
if name = 'main':

Try one of the many tutorials on the web. The correct way for "name = main" is towards the bottom.

Edited 4 Years Ago by woooee: url

This article has been dead for over six months. Start a new discussion instead.