python web programming for PHP programmers
ajaksu at gmail.com
Wed Dec 24 16:49:53 CET 2008
On Dec 24, 12:40 pm, Nikola Skoric <nick-n... at net4u.hr> wrote:
> I0m a python newbie with PHP background. I've tried to make a web app
> from one of my python scripts (which I haven't done before) and I
> ended up with:
> echo shell_exec("python foobar.py");
> which works really nice :-D
Python can work in a similar way to PHP if your server supports it,
but Python also allows you to create the server itself.
> For some reason I can't find no "quick and dirty python web
> programming tutorial for PHP programmers" on google. :-D I don't need
> a general python tutorial, I just need a tutorial on how to make a
> hello world server side script with python. Any suggestions?
See http://webpython.codepoint.net/cgi_hello_world for a very
primitive way (and docs here: http://docs.python.org/dev/library/cgi.html
A better way, that uses a trivial Python-based server:
from wsgiref.simple_server import make_server
def hello_app(environ, start_response):
start_response("200 OK", [('Content-Type','text/plain')])
return "Hello world!"
httpd = make_server('', 8000, hello_app)
print "Serving HTTP on port 8000..."
$ python hello.py
Serving HTTP on port 8000...
localhost - - [24/Dec/2008 13:11:32] "GET / HTTP/1.1" 200 12
You can use better Python-based servers with handy features for
Now, to ease things, you can have Python working more like PHP.
First, server support. What HTTP server are you using? For starting
up, mod_python (http://www.modpython.org/) isn't that bad, but there
are better alternatives: http://code.google.com/p/modwsgi/ ,
http://pypi.python.org/pypi/python-fastcgi/1.1 and http://python.ca/scgi/
Then, there are many ways of getting the PHP feel (embedding in pages,
http://snakelets.sourceforge.net/ (development stopped)
More information about the Python-list