DTML<->Python confusion (RE: [Zope] How to make a script return rendered dtml)

Bjorn Stabell bjorn@exoweb.net
Thu, 14 Jun 2001 13:30:14 +0800


Wow, thanks Evan.  I should've asked these questions a long time ago...

From: Evan Simpson [mailto:evan@digicool.com]
> From: "Bjorn Stabell" <bjorn@exoweb.net>
> > How do you do dtml-with and dtml-let in a Python script?  (I.e.
> > put something on the namespace)
>=20
> You can't.  Scripts can use the DTML namespace in the same=20
> way that Python expressions in DTML can, but that's it.
>=20
> On the other hand, you can create (and pass along) all the=20
> local variables you want.

Is it possible to append an object to the namespace?  Isn't that what
dtml-with does?

> > How do you give positional (not keyword) arguments to a DTML
> > method; is there any difference?
>=20
> Keyword arguments are put on top of the namespace.  You can't=20
> use positional arguments, except the standard (None, _) idiom.
> DTML was  never meant to pass arguments around, that's what
> the namespace is for, for what that's worth :-P

But the other way around, calling Python functions from DTML (via
<dtml-var func>) the positional arguments are gotten from the namespace,
right?

[... good andswer to __call__ et al deleted :) ... ]
> > When does RESPONSE need to be passed; it can always be gotten
> > from the REQUEST, right?
>=20
> Right.

So why do so many DTML methods / documents have REQUEST as an explicit
argument?  It looks like a convention that has to mean something.

> > Are namespace, _, REQUEST, and context just different names for
> > the same thing?
>=20
> Not quite.  The namespace, accessible in DTML as "_", is a=20
> pile of objects.
> The REQUEST is a particular object created by ZPublisher to=20
> hold information
> about the request, such as form variables and URL=20
> information.  The context
> (or client, for DTML) is the object on which the method was=20
> called.  If the
> DTML Method is the target of the request, or if you pass a=20
> client as the
> first argument when calling it, the Method pushes it onto the=20
> namespace.
> Also, the context (like any other Zope object) is acquisition=20
> wrapped.  The
> ultimate acquisition parent of any publsihed object is a=20
> special wrapper for
> REQUEST.  All this means that when you ask the namespace for=20
> the name "foo",
> it will end up looking for it in the context, in the=20
> context's containers
> all the way to the root, and the REQUEST.

I am a little bit confused about the fact that the acquisition path is
related to how the document was called, not just to the containment
relationships it is involved in.  Or is it?  myobj.aq_parent isn't
necessarily the object that contains myobj?

Is the namespace stack basically the same as the acquisition path?

Bye,
--=20
Bjorn