Python CGI programming on Mac OSX

Joined
May 21, 2015
Messages
2
Reaction score
1
Hello I am using Mac OSX mavericks and I am new to apache2 and cgi, but have been using python for a while now.

My python script called hello.py in the cgi-executable folder is:

#!/anaconda/bin/python
import cgi, cgitb
form = cgi.FieldStorage()
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print"Content-type:text/html\r\n\r\n"
print"<html>"
print"<head>"
print"<title>Hello - Second CGI Program</title>"
print"</head>"
print"<body>"
print"<h2>Hello %s %s</h2>"%(first_name, last_name)
print"</body>"
print"</html>"

my form.html file is:

<formaction="/cgi-bin/hello.py"method="get">
First Name: <inputtype="text"name="first_name"><br/>
Last Name: <inputtype="text"name="last_name"/>
<inputtype="submit"value="Submit"/>
</form>

But the input from the form doesn't go through to the python script!
but if i execute localhost/cgi-bin/hello.py?first_name=F&last_name=L
it displays HELLO F L

please tell me where to place the form.html file so it can find the hello.py cgi script

I have looked at stack overflow a lot and not found any solution. Please help!

The hello.py is in the cgi-executables folder
 
Joined
Sep 26, 2015
Messages
1
Reaction score
0
hi, Roy,
I have the same problem with you. Have you solved it yet?

Hello I am using Mac OSX mavericks and I am new to apache2 and cgi, but have been using python for a while now.

My python script called hello.py in the cgi-executable folder is:

#!/anaconda/bin/python
import cgi, cgitb
form = cgi.FieldStorage()
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print"Content-type:text/html\r\n\r\n"
print"<html>"
print"<head>"
print"<title>Hello - Second CGI Program</title>"
print"</head>"
print"<body>"
print"<h2>Hello %s %s</h2>"%(first_name, last_name)
print"</body>"
print"</html>"

my form.html file is:

<formaction="/cgi-bin/hello.py"method="get">
First Name: <inputtype="text"name="first_name"><br/>
Last Name: <inputtype="text"name="last_name"/>
<inputtype="submit"value="Submit"/>
</form>

But the input from the form doesn't go through to the python script!
but if i execute localhost/cgi-bin/hello.py?first_name=F&last_name=L
it displays HELLO F L

please tell me where to place the form.html file so it can find the hello.py cgi script

I have looked at stack overflow a lot and not found any solution. Please help!

The hello.py is in the cgi-executables folder
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top