2011-03-26 157 views
2

只是做与HTML文件中的基本Python项目,我碰到这给了有关如何我可以执行代码的想法的教程,Python的CGI脚本不执行

这里是HTML代码

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
    <meta content="text/html; charset=ISO-8859-1" 
http-equiv="content-type"> 
    <title>Admin Login</title> 
</head> 
<body> 
<big><big>Login 
Here<br> 
<br> 
</big></big> 
<form action="/var/www/cgi-bin/Login.py" name="LoginForm"><big>Administration 
Login<br> 
User Name<br> 
    <input name="UserName"><br> 
    <br> 
    <br> 
Password<br> 
    <input name="PassWord"><br> 
    </big><br> 
    <br> 
    <br> 
<input type="submit"> 
    <br> 
</form> 
&nbsp;__&nbsp;<br> 
</body> 
</html> 

和Python代码..

#!/usr/bin/python 
import cgi 
import cgitb; cgitb.enable() 
# get the info from the html form 
form = cgi.FieldStorage() 
#set up the html stuff 
reshtml = """Content-Type: text/html\n 
<html> 
<head><title>Security Precaution</title></head> 
<body> 
""" 

print reshtml 

User = form['UserName'].value 
Pass = form['PassWord'].value 

if User == 'Myusername' and Pass == 'MyPasword': 
    print '<big><big>Welcome' 
    print 'Hello</big></big><br>' 
    print '<br>' 
else: 
    print 'Sorry, incorrect user name or password' 

print '</body>' 
print '</html>' 

的问题是,当我提交的用户名和密码,它只是显示整个代码回到了浏览器,而不是需要欢迎消息:(我用Fedora1 3 ..谁能告诉我哪里出了问题?我甚至改变了文件的权限。

回答

3

很可能,您的网络服务器未配置为执行脚本。即使它在文件系统中被标记为“可执行文件”,这并不一定意味着网络服务器知道它应该执行.py文件(而不是直接为它们提供服务)。看看这里,如果你正在运行的Apache:http://httpd.apache.org/docs/2.0/howto/cgi.html

2
<form action="/var/www/cgi-bin/Login.py" name="LoginForm"> 

尝试

<form action="/cgi-bin/Login.py" name="LoginForm"> 

的/ var/www是可能从您的FTP站点的路径。 Web服务器只会查看/ var/www,因此它会自动将该部分放在那里。