Inserting Python commands into HTML documents

Alex Martelli aleax at aleax.it
Mon Apr 14 03:29:33 EDT 2003


<posted & mailed>

Em wrote:

> Hello,
> 
> I am an extremely new member of the Python family. I had a job interview
>   where they charged me with the task of creating a (fake) corporate
> website using Python in ten days--with two left now.

Ouch!  What happened to the other eight days?!


> The problem is that what I have read seems to say Python is a CGI
> language... Am I remiss in believing that my website is going to be
> completely run from inside a couple .PY files in the CGI-BIN?

CGI is probably fastest to program, for simple cases, if you know
what you're doing -- and Python's indeed quite suitable for writing
CGI scripts.  But, you do have oodles of other possibilities.


> Is there a way for it to act more like PHP, as in run Python commands
> from inside the (index|contacts|about|etc).html or at least simulate
> that behavior? (This is on a linux server and I am not to use PHP, FYI.)

Sure, there are many ways in which you can choose to use this
debatable "let's mix logic right inside presentation so we can't
easily separate them any more" approach (perhaps excusable when
one's in a deuced hurry, if one's used to it and thus can deploy
it fastest).  My suggestion would be to use "Webware for Python"
and specifically its Webkit component -- I think it will be easiest
for you to download and deploy, particularly because, if need be,
you can drive Webware from any server via CGI, while still leaving
you with a choice of programming models for your Python scripts
("PSP" embedding Python inside HTML, servlets a la Java, templates
[ideally with Cheetah, but other templating approaches are also
well integrable with Webware]...).


Of course, the richness of choices -- which is a blessing in many
respects -- may mean you need TIME to evaluate then and choose
the one most suitable for you... just what you don't have right
now with 2 days' left!  So I suggest you just go for Webware.
Use it's "oneshot" interfacing when you're developing to ensure
all mods you're doing to the pages or servlets ARE picked up
automatically...


Alex





More information about the Python-list mailing list