0
votes

I am teaching a year 11 class how to write dynamic webpages, using lighttpd and python on ubuntu. In my /var/www/cgi-bin I have one python file (testing.py), which gets executed and I see the output in the browser. I have another python file (greet.py) which is supposed to process a form(form1), but I get a "500 - internal server error". It is not 404, so I believe the server is accessing the (file greet.py) but is having some problem.

The file /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>

The file /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>")

The file /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>

This is the file /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>")

I see the output of the /var/www/cgi-bin/testing.py. But when I submit the form1, I get "500 - Internal Server Error'. Is there something I am missing. Both the files in cgi-bin have same permissions. Thanks in advance. sonip

1
Yes, you are missing at least some quotes for your string literals in the last two lines of greet.py. - Wombatz

1 Answers

0
votes

I got it working. All it needed was one import cgi statement in the greet.py.

sonip