簡體   English   中英

使用python的CGI表單提交按鈕

[英]CGI form submit button using python

我正在嘗試創建一個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>

有誰知道如何使用cgi創建提交按鈕? 這是我到目前為止所擁有的。

import cgi
import cgitb
cgitb.enable()


form = cgi.FieldStorage()

keyword = form.getvalue('keyword')

要從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>'

然后在您的next.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>'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM