我的python代码不返回页面?关注HTML表单

我的python代码不返回页面?关注HTML表单,python,Python,对于学校项目,我需要使用表单构建页面。但是,我的代码不返回页面。相反,它只返回.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

对于学校项目,我需要使用表单构建页面。但是,我的代码不返回页面。相反,它只返回.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.
#/usr/bin/python
打印“内容类型:文本/html”
打印
#5月17日
导入cgi,cgitb
cgib.enable()
form=cgi.FieldStorage()
#5月19日
dataset1=open('Book1.csv','r')
dataset2=open('Race Demographic by state.txt','r')
来源=“”
来源! ''' def数据分离器(x): data=x.read() 返回数据。拆分(“\n”) def datdatamang(x): 数据=数据剥离器(x) 索引=0 WhileNumber=0 而指数
您在哪种web服务器上运行此功能?它是否配置为将Python脚本视为CGI程序?程序是否需要一个
.cgi
扩展和/或使其可执行?您是否已设置web服务器以执行cgi脚本?哦。我忘了在我的网络服务器上运行这个。现在让我尝试一下,看看它是否有效。我在web服务器上运行此程序时仍然遇到问题,因为当我提交HTML表单时,它只是打印出.txt版本的代码。这是指向我正在使用的web服务器应用程序的链接: