lighttpd:cgi-bin中的简单python代码可以工作,但不处理表单

问题描述 投票:0回答:1

我正在教一年11班如何编写动态网页,在ubuntu上使用lighttpd和python。在我的/ var / www / cgi-bin中,我有一个python文件(testing.py),它会被执行,我在浏览器中看到输出。我有另一个python文件(greet.py),它应该处理一个表单(form1),但我得到一个“500 - 内部服务器错误”。它不是404,所以我相信服务器正在访问(文件greet.py)但是有一些问题。

文件/var/www/html/index.html:

<!DOCTYPE html>
<html>
<title>This is from the html file</title>
<body>Testing<br>
<a href="/cgi-bin/testing.py">This should show the output of python file in /var/www/cgi-bin </a><br>
<a href="form1.html">Form1</a>
</body>
</html>

文件/var/www/cgi-bin/testing.py:

#! /usr/bin/python
print("<!DOCTYPE html>")
print("<html>")
print("<title>")
print("Testing from cgi-bin")
print("</title>")
print("<body>")
print("This is testing from /var/www/cgi-bin/")
print("</body>")
print("</html>")

文件/var/www/html/form1.html:

<!DOCTYPE html>
<html>
<title>Form Testing </title>
<body>
<form method="POST" action="/cgi-bin/greet.py">
Name: <input type="text" name="fname">
<input type="submit" value="submit">
</form>
</body>
</html>

这是文件/var/www/cgi-bin/greet.py:

#!/usr/bin/python
form=cgi.FieldStorage()
name = form['fname'].value
print("<!DOCTYPE html>")
print("<html>")
print("<title> greet - form processed</title>")
print("<body>")
print("Hello "+name.title())
print(<"/body>")
print("</html>")

我看到了/var/www/cgi-bin/testing.py的输出。但是当我提交form1时,我得到“500 - 内部服务器错误”。是否有我遗漏的内容.cgi-bin中的文件都具有相同的权限。提前感谢.sonip

python cgi lighttpd
1个回答
0
投票

我搞定了。它所需要的只是greet.py中的一个import cgi语句。

sonip

© www.soinside.com 2019 - 2024. All rights reserved.