More on web development

Sam Penrose spenrose at well.com
Sun Jan 14 21:39:03 EST 2001


In article <0hr16t4gt4vp72b8aqcs0tup6ddcs1urtr at 4ax.com>, Tim Roberts 
<timr at probo.com> 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.
> 
> 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.
> 
> 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?
> 
> 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?
> --
> - Tim Roberts, timr at probo.com
>   Providenza & Boekelheide, Inc.

0) The answer depends on the details of what you are trying to do and 
the resources you have to do it with. That may sound pedantic, but there 
really is no "right" way to do Python web development.

1) Our larger systems maintain global "state" using a database, and 
place constants in a single file which is imported by everything. If you 
really need persistent Pythonic state, I would think CGI is not the 
right tool. At least, I'm not clear on how you "pass the global class 
instance" from one process to another. I suppose if you were using a 
threaded CGI server that might work.

2) Vis-avis HTML, we use a mixture of session keys/ids in HTML to 
reference state which is recorded in the database plus hidden HTML 
fields for data which is more conveniently stored client side.



More information about the Python-list mailing list