Creating Python Scripts on MAMP

I use the mamp server to test all my web pages. I am new to python. I can run the script in the python interpreter, which usually prints the hello world.

print "Hello World!" 

So, I used the same line in a file called test.py. So, how should I run this on the Internet.

As I wrote in python, I tried some common things by putting test.py in / htdocs / cgi-bin / and trying to open it. But this speaks of a forbidden page.

Someone please help me do this work. Thanks

+6
python web-applications mod-python
source share
2 answers

To do this using CGI, I recommend reading the Python CGI docs . At a minimum, you need to infer the content type and html tags:

 print "Content-Type: text/html" print print "<html>" print "<head>" print "<title>Example of Python CGI script</title>" print "</head>" print "<body>" print "Hello World!" print "</body>" print "</html>" 

Also, verify that the web server software has permission to execute the script. You should be able to use chown to set ownership and chmod to set permissions .

+5
source share

Know that this is an old post, but I will add two cents.

I put my * .py scripts in / Applications / MAMP / cgi -bin

run my scripts with #! / bin / usr / python

  print "Content-type:text/html \r\n\r\b" 

then chmod 755.py and run it with. /.py from the cgi-bin directory

Hope this helps :)

+1
source share

All Articles