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

时间:2019-04-29 23:25:35

标签: python cgi lighttpd

我正在教11年级的课程,如何在ubuntu上使用lighttpd和python编写动态网页。 在我的/ var / www / cgi-bin中,我有一个python文件(testing.py),该文件被执行,并且在浏览器中看到输出。我还有另一个python文件(greet.py),该文件应该处理form(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/ww/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-Internal Server Error”。 有什么我想念的吗? cgi-bin中的两个文件都具有相同的权限。 提前致谢。 Sonip

1 个答案:

答案 0 :(得分:0)

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

sonip