带有两个提交按钮的Python CGI脚本

时间:2017-10-12 17:28:27

标签: python html cgi

我想在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..."

1 个答案:

答案 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>"