More on web development

Paul Boddie paulb at infercor.no
Mon Jan 15 08:05:39 EST 2001


Tim Roberts wrote:
> 
> The recent thread on web development techniques and templating vs
> Python-as-HTML has been very helpful.  I wonder if I might explore
> another aspect of this, which actually relates more to using Python in
> larger applications.

I would point you to the Web modules overview page I did, but the pages have
been mislaid in an upgrade at the hosting provider, I think. I still have a
slightly older copy if you're interested, though.

> There are a number of ways to architect a Python-based web site with
> many pages.  I have tended to build my site with one script per page, so
> that the URL simply points to the .py file.  I'm now realizing this has
> a number of disdvantages.  For one thing, it can be difficult to share
> global state. I've tried to put common things, including instances of
> global data, into a "common.py", but since common.py has to be imported
> into almost every file, there seem to be multiple instance issues.

Indeed. Unless you're using a framework with or within the Web server which
orchestrates the accesses to each of those programs, and has only one instance
of "common.py" around, it's likely that many Python processes will be created
and each of those will have its own instance of "common.py" (or more
appropriately, the "common" module).

> I'm wondering now if it would be better to have the whole site
> dispatched by a single script, using the PATH_INFO part of the URL to
> identify a command to be executed.  Does anyone have any feelings about
> this?

This has been done a lot since the days of Bobo (ZPublisher). However, it's
probably best not to roll your own framework unless you're completely aware of
the security risks of having the URL determine the "command" or function to be
executed. For example, if you decide that a URL can indicate a module to be
imported and a function to be invoked, it is essential that the choice of
modules to be imported and the choice of functions to be invoked is restricted
in some way. Otherwise, someone could use a URL which imports the "os" module
and invokes the "system" function.

> I'm also considering switching my global state from module-based to
> class instance-based.  The biggest advantage to this, it seems to me, is
> that I no longer need to worry about importing my common.py everywhere.
> I can pass the global class instance around and call the methods without
> the import, and without worrying about nested import dependencies.
> 
> Any advice from the more experienced Python web developers?

I would use one of the existing frameworks myself. Indeed, I'm currently rather
interested in Webware - it seems to be fairly easy to understand and extend.

Regards,

Paul



More information about the Python-list mailing list