使用python的CGI表单提交按钮

使用python的CGI表单提交按钮,python,cgi,Python,Cgi,我正在尝试创建一个cgi表单,允许用户输入一个单词,然后它会将该单词发送到下一页(另一个cgi)。我知道如何使用.html文件,但当涉及到使用python/cgi时,我就不知所措了 这里是我需要做的,但它是在html <html> <h1>Please enter a keyword of your choice</h1> <form action="next.cgi" method="get"> Keyword: <input type="

我正在尝试创建一个cgi表单,允许用户输入一个单词,然后它会将该单词发送到下一页(另一个cgi)。我知道如何使用.html文件,但当涉及到使用python/cgi时,我就不知所措了

这里是我需要做的,但它是在html

<html>
<h1>Please enter a keyword of your choice</h1>
<form action="next.cgi" method="get">
Keyword: <input type="text" keyword="keyword">  <br />
<input type="submit" value="Submit" />
</form>
</html>

要从Python cgi页面显示html,需要使用print语句

下面是一个使用您的代码的示例

#!/home/python
import cgi
import cgitb
cgitb.enable()

print 'Content-type: text/html\r\n\r'
print '<html>'
print '<h1>Please enter a keyword of your choice</h1>'
print '<form action="next.cgi" method="get">'
print 'Keyword: <input type="text" name="keyword">  <br />'
print '<input type="submit" value="Submit" />'
print '</form>'
print '</html>'
#/主页/python
导入cgi
进口cgitb
cgib.enable()
打印“内容类型:text/html\r\n\r”
打印“
打印“请输入您选择的关键字”
打印“
打印“关键字:
” 打印“ 打印“ 打印“
然后在下一个.cgi页面上,您可以获得表单提交的值。比如:

#!/home/python
import cgi
import cgitb
cgitb.enable()

form = cgi.FieldStorage()

keyword = form.getvalue('keyword')

print 'Content-type: text/html\r\n\r'
print '<html>'
print keyword
print '</html>'
#/主页/python
导入cgi
进口cgitb
cgib.enable()
form=cgi.FieldStorage()
关键字=form.getvalue('keyword')
打印“内容类型:text/html\r\n\r”
打印“
打印关键字
打印“

非常感谢,这正是我想要的!
#!/home/python
import cgi
import cgitb
cgitb.enable()

form = cgi.FieldStorage()

keyword = form.getvalue('keyword')

print 'Content-type: text/html\r\n\r'
print '<html>'
print keyword
print '</html>'