所以我正在尝试测试我的代码并进行了一些更改,但每次我收到'500内部服务器错误'。我不知道我做错了什么。我也不知道在哪里可以找到更好的错误描述。
感谢。
编辑:在底部添加了代码。
这是我的代码:
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
new = open("survey.ssv", "r+")
new.write(form.getvalue("surveyQuestion")+"\n")
new.seek(0)
lines = new.readlines()
i = 0
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Create-a-Survey!</title>"
print "</head>"
print "<body bgcolor='white' text='black'>"
print "<center>"
print "<h1>Create Survey Page</h>"
print "</center>"
print "To create a survey first input a title in the 'Survey Title' text box. To add questions, write a question in the 'Survey Question' text box and click the 'Add' button. If you want to create a new survey, write a new survey title and click 'New'. The 'Done' button will end the survey creation and return you to the welcome page."
print "<br><br>"
for line in lines:
if i == 0:
print "Current Survey Title:<br>%s" % line
print "<br><br>"
print '<form action="newSurvey.py" method="post">'
print 'Survey Title:<br><input type="text" name="surveyTitle">'
print '<input type="submit" name="decision" value="New">'
print '</form>'
print '<br><br>'
else:
print "Question %d:<br>%s" % i, % line
print '<br><br>'
i = i + 1
new.close()
print '<form action="addQuestion.py" method="post">'
print 'Survey Question:<br><input type="text" name="surveyQuestion">'
print '<br><br>'
print '<input type="submit" name="decision" value="Add">'
print '</form>'
print '<form action="doneSurvey.py" method="post">'
print '<input type="submit" name="decision" value="Done">'
print '</form>'
print '<a href="welcome.html">Back to welcome page</a>'
print '</body>'
print '</html>'
这是当前正在运行的代码,是我在上面的代码之前运行的代码:
#!/usr/bin/python
import cgi
import cgitb; cgitb.enable() # enable debugging mode
form = cgi.FieldStorage()
new = open("survey.ssv", "r+")
new.write(form.getvalue("surveyQuestion")+"\n")
lines = new.readlines()
i = 0
print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Create-a-Survey!</title>"
print "</head>"
print "<body bgcolor='white' text='black'>"
print "<center>"
print "<h1>Create Survey Page</h>"
print "</center>"
print "To create a survey first input a title in the 'Survey Title' text box. To add questions, write a question in the 'Survey Question' text box and click the 'Add' button. If you want to create a new survey, write a new survey title and click 'New'. The 'Done' button will end the survey creation and return you to the welcome page."
print "<br><br>"
for line in lines:
if i == 0:
print "Current Survey Title:<br>%s" % line
print "<br><br>"
print '<form action="newSurvey.py" method="post">'
print 'Survey Title:<br><input type="text" name="surveyTitle">'
print '<input type="submit" name="decision" value="New">'
print '</form>'
print '<br><br>'
else:
print "Question %d:<br>%s" % i, % line
print '<br><br>'
i = i + 1
new.close()
print '<form action="addQuestion.py" method="post">'
print 'Survey Question:<br><input type="text" name="surveyQuestion">'
print '<br><br>'
print '<input type="submit" name="decision" value="Add">'
print '</form>'
print '<form action="doneSurvey.py" method="post">'
print '<input type="submit" name="decision" value="Done">'
print '</form>'
print '<a href="welcome.html">Back to welcome page</a>'
print '</body>'
print '</html>'
答案 0 :(得分:1)
此行无效Python:
print "Question %d:<br>%s" % i, % line
如果要插入两个值,请使用元组:
print "Question %d:<br>%s" % (i, line)