samedi 20 novembre 2010

SPMPT for python programmers

Hello,



today I will move lights on hidden feature provied by SPMPT. When I release the first version of SPMPT, my main intention was to make installation of Trac and Subversion easly for evry developpers. But with time and users feedback, I know now, Python programmers using Mac found in SPMPT a great and easy tool to install python on Mac. So this is a little "Hello world" tutorial for people who used SPMPT, and want to try python in MAMP.




Apache configuration

First you have to prepare the environment, you need to create a Directory in Apache.
create a new file, for example mypython.conf

<IfModule !mod_python.c>
  LoadModule python_module     modules/mod_python.so
</IfModule>
 
<Directory /Applications/MAMP/htdocs/python-hello>
 AddHandler python-program .py
    PythonHandler hello 
 PythonDebug On #for developpemnet enable debug
</Directory>


Your first program

You have to create the python-hello folder in /Applications/MAMP/htdocs/

now we will create the python script : /Applications/MAMP/htdocs/python-hello/hello.py


01. from mod_python import apache
02.  
03. def handler(req):
04.  req.content_type = "text/html"
05.  req.send_http_header()
06.  req.write('<html><body>')
07.  req.write("Hello<br/>")
08.  req.write("This is a loop for in python : <br/>")
09.  a = ['cat', 'window', 'defenestrate']
10.  for x in a:
11.  req.write(x)
12.  req.write('<;br/>')
13. req.write('</body></html>')
14. return apache.OK



For advanced programmers, Django is recommended.


I'm not a python programmer so, if you have some questions, ask google.


Aucun commentaire:

Enregistrer un commentaire