Mailing List Archive

python active web pages
hi there,

i'm looking to embed python into web pages in a similar way to ASP and
PHP3 and so forth.

i found a thing called Active Server Python,

<http://starship.skyport.net/crew/ejohn/asp/>,

but i note that it doesn't seem to have had any attention in the last year.

i also looked at ZTemplates (a component of Zope),

<http://www.zope.org/Download/ZTemplates/>,

and while it doesn't actually embed python, it has a limited embedding
language of its own, DTML, which gets munged into python. i must say that
DTML looks a bit hideous (if anyone from digicool is reading, sorry guys).

anyone have any experience with active web pages using either of these or
something else?

thanks in advance,

:-j

--
jonathan hogg, one good idea limited, 25 clouston street, glasgow g20 8qr, uk
jonathan@onegoodidea.com www.onegoodidea.com t:(0)976-614338 f:(0)7970-537451
python active web pages [ In reply to ]
> i also looked at ZTemplates (a component of Zope),
>
> <http://www.zope.org/Download/ZTemplates/>,
>
> and while it doesn't actually embed python, it has a limited embedding
> language of its own, DTML, which gets munged into python. i must say that
> DTML looks a bit hideous (if anyone from digicool is reading, sorry guys).

Well, DTML (especially outside of Zope) is not meant to be
scripting-inside-of-HTML, which most Active Server Page type things are.
Personally, I think that is beyond hideous, the

<HTML>
<%
document.write('<HEAD>')
document.write('<TITLE>%s</TITLE>' % someTitleString)
...
</HTML>

is terrible (i have seen plenty of PHP source that looks like the above).
DTML Scripting can look quite ugly, but it's (a) safe (which is good
because DTML in Zope and even on its own can be edited through the web and
you have security issues with that), and (b) very powerful depending on the
namespace given it (which is very powerful in Zope due to the inherent
Acquisition model).

Using ZPublisher (the beast previously known as Bobo) and DocumentTemplates
is very powerful for web development. The DocumentTemplates are meant to
be _views_ on an Object, not just a web page unto themselves. Thus, DTML
has a lot of very powerful batch processing features (it's basically a
reporting language in its web form) and very powerful namespace features.

This seperation (which was most effective before DTML scripting, aka the
embedding of python expressions in DTML, was implemented into DTML) is very
powerful as it enforces the seperation of Code and Presentation, a rather
MVC (Model-View-Controller) style paradigm.

My first Bobo app was turning a socket server into a web application.
Since I had made my classes and the views on those classes rather seperate
in the socket server implementation, turning into a web app took only a
matter of hours. I was able to make a very simple DTML page for displaying
results from a search form and focus on implementing some new methods
needed for this new way of accessing data. Once those methods were
implemented, I was able to spend the rest of the day in web-designer mode
since I already knew all the data that I had available to me and I could
just write DTML and not even have to think about Python.

That was very very _VERY_ powerful to me.

I wouldn't have had such an easy (nor as fun or as flexible) time in an ASP
type environment where all the code is embedded on a page. Granted, you
can write ASP type pages that import modules and use the beautifully simple
<%= foo %> and have a similar abstraction, but it's not built into the
system.

DTML (esp. DTML Scripting) has gotten rather beyond control in some cases,
but I believe it's the most "right". But yes, I work for digital creations
so I'm a bit biased.

But all that bias is based on the first time I wrote a major application
and just how _EASY_ (and powerful) that was.

Viva MVC !

> anyone have any experience with active web pages using either of these or
> something else?

yes. :)

.jPS | jeffrey@digicool.com
zope, through the web. www.zope.org
python active web pages [ In reply to ]
> i also looked at ZTemplates (a component of Zope),
>
> <http://www.zope.org/Download/ZTemplates/>,
>
> and while it doesn't actually embed python, it has a limited embedding
> language of its own, DTML, which gets munged into python. i must say that
> DTML looks a bit hideous (if anyone from digicool is reading, sorry guys).

ZTemplates, aka DTML Syntax is this::

<!--#var foo-->

DTML Scripting is this::

<!--#var "foo(bar=something + _['sequence-item']"-->

It's not munged into python, it IS python. It's just expressions, and it's
run through a Safe Evaluator (that (in Zope) works with security machinery,
and tries to prevent things like infinite recursion and some other
potentially unsafe things).

Just wanted to clear that up.

In Zope where everything can potentially be managed through the web and
control can be turned over to other people, the safety of expressions and
hook-ins to the Zope security machinery is a very powerful notion.

.jPS | jeffrey@digicool.com
zope, through the web. www.zope.org
python active web pages [ In reply to ]
Jonathan Hogg wrote:
>
> hi there,
>
> i'm looking to embed python into web pages in a similar way to ASP and
> PHP3 and so forth.
>
take a look at <http://starship.python.net/crew/mhammond/>
python active web pages [ In reply to ]
In article <7j98g1$atj$1@autumn.news.rcn.net>, "Jeffrey P Shell"
<jeffrey@Digicool.com> wrote:

>Well, DTML (especially outside of Zope) is not meant to be
>scripting-inside-of-HTML, which most Active Server Page type things are.
>Personally, I think that is beyond hideous, the
>
><HTML>
><%
> document.write('<HEAD>')
> document.write('<TITLE>%s</TITLE>' % someTitleString)
> ...
>%>
></HTML>
>
>is terrible (i have seen plenty of PHP source that looks like the above).

i couldn't agree more. this is what i'm trying to avoid. the most simple
model is to execute python scripts from CGI and build web-pages using
something like HTMLgen or just writing out bits of HTML as strings and
sticking in the dynamic bits in between. this is basically what the ASP
you show above does (hence making the use of ASP quite pointless in my
book).

>This seperation (which was most effective before DTML scripting, aka the
>embedding of python expressions in DTML, was implemented into DTML) is very
>powerful as it enforces the seperation of Code and Presentation, a rather
>MVC (Model-View-Controller) style paradigm.

it's the separation that i'm not sure i want. i have skimmed through the
DTML manual on your web pages and believe i understand (to a first
approximation) how it operates. the problem is that i'm not using the rest
of Zope and if i want to execute setup code, rather than just evaluate
expressions within <#var expr> tags, then i'd need to stick this into a
separate script which sucks in the template and passes in whatever data as
variables.

what i'd really like to be able to write is stuff along the lines of:

<%
import foobar

your_name = foobar.frib( frob = "all" )
nee = foobar.noneshallpass( what is your_name )

<html>
<head>
<title>Wotnot</title>
</head>
<body>
"We are the knights who say... <%= nee %>
</body>
</html>

all well and good. looks like "asp" can do this fine. but unfortunately it
won't allow me to do the *really* useful bits that ZTemplates supports:

<h1>How do I love thee?</h1>
<ol>
<!--#in ways -->
<li> <!--#var way -->
<!--#\in -->
</ol>

don't get me wrong, while i think the above is a *bit* hideous, it is
undeniably powerful and very close to what i'm looking for.

>My first Bobo app was turning a socket server into a web application.
>Since I had made my classes and the views on those classes rather seperate
>in the socket server implementation, turning into a web app took only a
>matter of hours. I was able to make a very simple DTML page for displaying
>results from a search form and focus on implementing some new methods
>needed for this new way of accessing data. Once those methods were
>implemented, I was able to spend the rest of the day in web-designer mode
>since I already knew all the data that I had available to me and I could
>just write DTML and not even have to think about Python.

a very valid point of view. to be honest, how much the integration of
control and interaction will be a pain in the arse is still to be tested.

>DTML (esp. DTML Scripting) has gotten rather beyond control in some cases,
>but I believe it's the most "right". But yes, I work for digital creations
>so I'm a bit biased.
>
>But all that bias is based on the first time I wrote a major application
>and just how _EASY_ (and powerful) that was.

's ok, we all have our biases. these are still the sort of opinions i was
hoping to garner. thanks for your comments.

does anyone else use active web pages? surely all you python/web hackers
don't just use CGI scripts?

:-j

--
jonathan hogg, one good idea limited, 25 clouston street, glasgow g20 8qr, uk
jonathan@onegoodidea.com www.onegoodidea.com t:(0)976-614338 f:(0)7970-537451
python active web pages [ In reply to ]
In article <37582D9D.3D7A4B1D@hp.com.NOSPAM>, Bruce Wheeler
<NOSPAMbruce_wheeler@hp.com.NOSPAM> wrote:

>Jonathan Hogg wrote:
>>
>> hi there,
>>
>> i'm looking to embed python into web pages in a similar way to ASP and
>> PHP3 and so forth.
>>
>take a look at <http://starship.python.net/crew/mhammond/>

sorry, i should perhaps have made myself more clear. i was wondering as i
posted whether mention of ASP would confuse the matter.

i'm not implementing on Windows or using "Active Server Pages" as defined
by Microsoft. i'm interested in dynamic web pages on unix/apache.

thanks anyway,

:-j


(and yes, i know about PyApache - but that's just a
convenience/optimisation for CGI, not an embedding of Python in web pages)

--
jonathan hogg, one good idea limited, 25 clouston street, glasgow g20 8qr, uk
jonathan@onegoodidea.com www.onegoodidea.com t:(0)976-614338 f:(0)7970-537451
python active web pages [ In reply to ]
> does anyone else use active web pages? surely all you python/web hackers
> don't just use CGI scripts?

No, that's why Gods created Bobo ;-)

Actually, here's another alternative that's only gone non-updated since
late november:: (Uses JPython and Servlets)

http://www.dstc.edu.au/aspy/

A _long_ time ago (about three years methinks), I did something like all
this based on the only web application server/platform (besides Zope) that
I really respect, WebObjects, called Pummel.

It had a syntax for putting code on the page, and then addressing it later.
In that phase it was _fairly_ simple. But then it started trying to be a
little bit like Bobo (mainly:: i wanted more powerful components that I
could share). And once I actually figured out Bobo and DTML, I put the
project away. I don't even know where the source is anymore.

Basically, it looked like:

<HTML><HEAD>....
<APYML>
import foobar
import hti

hello=hti.Input(type='text', name='uname', value=uname)
</APYML>
</HEAD>
<BODY>
<FORM ACTION...>
<PYML NAME="hello"></PYML>
<INPUT TYPE="submit">
</FORM>
</BODY></HTML>

(hti was a very very very very simple HTMLGen-ish module without the smarts
that HTMLGen has. Remember this was many many many moons ago).

I'm about to unplug and go into a sooperfire weekend, but one quick
question: is there any reason why Zope isn't an option for what you're
doing? It seems like all these pseudo-ASP-ish projects get to about a 0.8
release functionality and then die off (my own PYML project included).
HTMLGen and Bobo seem to be the most widely supported and up-to-date
options from what I've seen over the past few years.

There used to be something called "Boilerplate" (Broilerplate?) listed on
the Python web site that did ASP-esque stuff too. Again, I don't know how
current the development is on that one either.

.jPS | jeffrey@digicool.com
zope, through the web. www.zope.org
python active web pages [ In reply to ]
jonathan@onegoodidea.com (Jonathan Hogg) writes:

> sorry, i should perhaps have made myself more clear. i was wondering
> as i posted whether mention of ASP would confuse the matter.

> i'm not implementing on Windows or using "Active Server Pages" as
> defined by Microsoft. i'm interested in dynamic web pages on
> unix/apache.

> (and yes, i know about PyApache - but that's just a
> convenience/optimisation for CGI, not an embedding of Python in web
> pages)

If someone were interested, it probably wouldn't take *too* much work
to convert my mod_dtcl to mod_pysomething.

The url is http://comanche.com.dtu.dk/dave/

I'd actually be interested in this myself, but I don't have any free
time:-(

Ciao,
--
David N. Welton, Web Engineer, Linuxcare, Inc.
415.354.4878 x241 tel, 415.701.7457 fax
dwelton@linuxcare.com, http://www.linuxcare.com/
Linuxcare. At the center of Linux.
python active web pages [ In reply to ]
One word: Zope!

www.zope.org


dwelton@linuxcare.com (David N. Welton) writes:

> jonathan@onegoodidea.com (Jonathan Hogg) writes:
> > i'm not implementing on Windows or using "Active Server Pages" as
> > defined by Microsoft. i'm interested in dynamic web pages on
> > unix/apache.
>