0

我的项目中有多个 .py 文件,除了我的survey.py 之外,它们都没有这样做。基本上,survey.py 是从 html 表单中获得信息的,我需要显示结果。我通过将调查答案的值附加到 .txt 文件来做到这一点。这在没有任何代码的情况下可以正常工作,并且信息会被附加,但是,当我尝试编写 html 时,我会收到 500 内部服务器错误。我已经看了一段时间的代码,我找不到任何错误。

#!/usr/bin/python
import cgi, cgitb
cgitb.enable()

form = cgi.FieldStorage()
page = 'Content-type: text/html\n\n'
one = open('1.txt', 'a')
two = open('2.txt', 'a')
three = open('3.txt', 'a')

one.write(form.getvalue('play'))
two.write(form.getvalue('instrument'))
three.write(form.getvalue('type'))

当我尝试这个时,我注意到信息被附加了,但是当我尝试在 html 中显示它时,如下所示:

a = open('1.txt', 'r')
b = open('2.txt', 'r')
c = open('3.txt', 'r')

aa = a.read()
bb = b.read()
cc = c.read()

page = 'Content-type: text/html\n\n'
page += '<html>'
page += '<head><title>Survey Results</title></head>'
page += '<body>'
page += '<h1> Survey Results </h1>'
page += '1) Do you play an instrument: <br>'
page += 'Yes:' + str(aa.count('yes')) + '<br>'
page += 'No:' + str(aa.count('no')) + '<br> <br>'
page += '</body> </html>'

我的权限也是正确的,我真的很困惑问题是什么。任何形式的帮助表示赞赏,谢谢。

4

0 回答 0