我想在python CGI中使用两个提交按钮。然后,CGI脚本将在稍后的同一脚本中执行不同的操作,具体取决于按下的按钮。此代码将显示2个按钮,但不等待我按下按钮。没有机会执行以下打印。怎么解决?
import cgi, cgitb
print "Content-Type: text/html\n"
print "<html>"
print "<input type='submit' value='Run from Server' name='Submit1' />"
print "<input type='submit' value='Run from VNC' name='Submit2' />"
print "</html>"
cgitb.enable()
form = cgi.FieldStorage()
if "Submit1" in form:
print "Button 1..."
elif "Submit2" in form:
print "Button 2..."
else:
print "nothing..."
答案 0 :(得分:0)
您似乎缺少表单标记...
print "Content-Type: text/html\n"
print "<html>"
print "<form>"
print "<input type='submit' value='Run from Server' name='Submit1' />"
print "<input type='submit' value='Run from VNC' name='Submit2' />"
print "</form>"
print "</html>"