[Tutor] Python and web scripting

Brad Chandler mbc2@netdoor.com
Tue, 19 Jun 2001 11:24:45 -0500


Does one actually write programs in Python when using Zope?  I've looked at
Zope briefly, but it looked overly complicated for simple web scripting and
I could never wrap my mind around how it was supposed to work.

There's something called PSP http://www.ciobriefings.com/psp/ , which stands
for Python Server Pages.  I think it's supposed to work similar to PHP.  It
looks promising, but I haven't figured out whether you can use it with
Python or whether you have to use the Java implementation of Python called
JPython.  (Can someone explain the reason for the exisitence of JPython? Why
would anyone use it? All I know about Java is the client side web stuff
which I hate with a passion).

I like programming in python better, but for web scripting it's hard to beat
PHP, especially if your using MySQL or PostgreSQL since PHP has some great
builtin functions for those databases, better than the ones available for
Python in my opinion.  I use PHP for all of my web scripting and Python for
utility programs that aren't used for the web.

You can of course use Python for cgi programs.  I've included an example of
an extremely simple one below.  The first two print statements are mandatory
I believe, after that you can program away.  I didn't actually need the
'import cgi' line in this example, but keep that module in mind.  You place
the script in your cgi-bin directory and access it by pointing your browser
to http://www.yourdomain.com/cgi-bin/test.py

At least that's how I access mine, assuming you named the file test.py and
made it executable.

#!/usr/bin/python

import cgi

print "Content-type: text/html"
print
print """
<html>
<head>
<title>Hello World!</title>
</head>
<body>
Hello World!<br>
</body></html>
"""

----- Original Message -----
From: "Flynt" <rhess@bic.ch>
To: "Michael" <michael@exasource.com>
Cc: <tutor@python.org>
Sent: Tuesday, June 19, 2001 9:00 AM
Subject: Re: [Tutor] Python and web scripting


> Michael wrote:
> >
> > Hi,
> >
> > I'm new to Python and new to programming.  I've done html and a few
> > javascripts and was wanting to learn a real programming language.  After
> > reading up on all the possibilities, I decided to learn Python as my
first.
> >
> > My question is, how is Python used in a web development application.
Can it
> > be used in the same manner, but instead of PHP?  Are there any tutorials
/
> > books that cover this aspect?
> >
> > Thanks,
> >
> > Michael
> >
> > PS I liked the IDLE tutorial, I've already learned some things from that
even
> > though it is not finished.
> >
>
> Hi Michael
>
>
> There is a nice package, HTMLgen
> (http://starship.python.net/crew/friedrich/HTMLgen/html/main.html),
> which helps you a lot writing HTML.
>
> There is an web application server based entirely on Python, called Zope
> (the link is http://www.zope.org/). This is a full featured web
> application server framework, for which also a lot of Add-On modules are
> already developed to handle special functionalities.
> You have to spend some time studying the docs, to see what it is capable
> of, but I think it is well worth a try. Because of the use of python, I
> think you are moving on much better founded ground than by using PHP,
> which might be quicker in the first place to implement but gives not as
> much back, when you are going to more involved problems. And, in IMO,
> PHP is *web only*, whereas with Python you can work in just all areas.
> A comprehensive introduction to Zope will come out right now at New
> Riders Publishing, the Zope Book by Amos Latteier and Michel Pelletier
> (search for "Zope" on amazon). You can have a look at the last draft of
> the book at
> http://www.zope.org/Members/michel/ZB/
>
> HTH
>
> --- Flynt
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor