0

对于一个学校项目,我需要使用表单构建一个页面。但是,我的代码没有返回页面。相反,它只以 .txt 形式返回我的代码。我不确定为什么会出现这个问题。这是我写的python代码错了吗?

#!/usr/bin/python
print "Content-type: text/html"
print

#May 17
import cgi, cgitb
cgitb.enable()

form=cgi.FieldStorage()

#May19
dataset1=open('Book1.csv','r')
dataset2=open('Race Demographic by state.txt','r')

sources='''<hr><h4>Sources!</h4><a     href="http://en.wikipedia.org/wiki/Demographics_of_the_United_States">Race Demographics</a>
<a href="http://voices.yahoo.com/average-sat-scores-state-2010-7702520.html?cat=4">SAT     Scores</a>
<a href="http://lisa.stuy.edu/~keiran.carpen/BriansDirectory/Sat scores by     state.txt">SAT Scores txt file</a>
<a href="http://lisa.stuy.edu/~keiran.carpen/BriansDirectory/Race Demographic by     state.txt">Race Demographics txt file</a></body></html>'''

def datasplitter(x):
    data = x.read()
    return data.split("\n")


def datdatamang(x):
    data = datasplitter(x)
    index = 0
    WhileNumber = 0
    while index < len(data):
        WhileNumber = 0
        string = data[index]
        string.split(" ")
        x=''
        while WhileNumber < len(string):
            if string[WhileNumber] == ',':
                x=x+'</td><td>'
            else:
                x=x+string[WhileNumber]
            WhileNumber+= 1
        ' '.join(string)
        data[index]='<tr><td>'+x+'</td></tr>'
        index+=1
    result=' '.join(data)
    result='''<table border='1'>'''+result+'</table>'
    return result
#May 19
def getDescription():
    page = ''
#May20
    if 'Submit' in form:
        if "Description" in form:
            page+= 'Ever since its conception, the SAT examinations have been widely     controversial.Many individuals believe that their race is the most intellectually superior,     and that their SAT scores reflect on their superiority. It is my job to find this     correlation between scores and race and end the battle among the races!'
        if "High SAT Scores" in form:
            page+= datdatamang('Book1.csv')
        if "Race Demographics" in form:
            page+= datdatamang('Race Demographics by state.txt')
        if "source" in form:
            page+= sources
#May 19

#May 20
print '''<!doctype html><title>SAT Analysis</title>'''
print '''<body>'''+getDescription()+'''</body></html>'''



#May 17 - Writing the analysisV2.html file and starting the code
#May 19 - Tables, and the like
#May 20 - Writing if statements, building the page.
4

0 回答 0