在自己的web服务器上运行python cgi脚本

时间:2014-01-21 20:05:33

标签: python apache2 cgi

我正在尝试运行这个简单的文件(from this tutorial

/var/www/cgi-bin/textarea.py:

#!/usr/bin/python

# Import modules for CGI handling
import cgi, cgitb

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from fields
if form.getvalue('textcontent'):
   text_content = form.getvalue('textcontent')
else:
   text_content = "Not entered"

print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>";
print "<title>Text Area - Fifth CGI Program</title>"
print "</head>"
print "<body>"
print "<h2> Entered Text Content is %s</h2>" % text_content
print "</body>"

/var/www/index.html:

<form action="/cgi-bin/textarea.py" method="post" target="_blank">
<textarea name="textcontent" cols="40" rows="4">
Type your text here...
</textarea>
<input type="submit" value="Submit" />
</form>

localhost我可以看到textarea但是在点击提交按钮后,firefox要我下载.py文件。

我在配置文件中添加了几行:

/etc/apache2/apache2.conf:

<Directory "/var/www/cgi-bin">
   AllowOverride None
   Options ExecCGI
   Order allow,deny
   Allow from all
</Directory>

<Directory "/var/www/cgi-bin">
Options All
</Directory>

我希望这是正确的配置文件,因为我没有httpd.conf 我错过了什么?

0 个答案:

没有答案
相关问题