我试图有两个不同的提交按钮。如果按下一个提交按钮,则它转到一个 cgi 脚本,如果按下另一个,则转到另一个。现在下面是我的代码,但它没有按我的意愿工作。无论按下哪个脚本,它们都只会转到相同的脚本。
#!/usr/bin/env python
import cgi
import cgitb
cgitb.enable()
form = cgi.FieldStorage()
keyword = form.getvalue('keyword')
keyset = set(x.strip() for x in open('keywords.txt', 'r'))
print 'Content-type: text/html\r\n\r'
print '<html>'
print "Set = ", keyset
print '<h1>If your keyword is in the set, use this submission button to retrieve recent tweets</h1>'
print '<form action="results.cgi" method="post">'
print 'Keyword: <input type="text" name="keyword"> <br />'
print '<input type="submit" value="Submit" name="Submit1" />'
print '</html>'
print 'Content-type: text/html\r\n\r'
print '<html>'
print '<h1>If your desired keyword is not in the set, use this submission button to add it</h1>'
print '<form action="inlist.cgi" method="post">'
print 'Keyword: <input type="text" name="keyword"> <br />'
print '<input type="submit" value="Submit" name="Submit2" />'
print '</html>'