[Zope] External method and stdout
Kapil Thangavelu
kthangavelu@earthlink.net
Tue, 05 Sep 2000 11:13:03 -0700
Andreas Pauley wrote:
>
> For some reason you have to "return" everything that should be available
> to zope. You can return a sequence and loop through it with DTML or you
> can build a variable with everything you want to display and then return
> the variable.
>
> I have no idea why this is so, and why you can't just the print
> statement as an equivalent to <dtml-var>.
>
> There is probably elegant ways of replacing DTML with external methods
> or Python Methods, I was just unable to find documentation and examples
> on it until now. Can anyone help with this?
>
> Regards,
> Andreas.
there are a couple of ways. first zope's publishing objects. if your
publishing a dtml method object than the semantics of it require that
values be inserted into the template/page thats being returned to the
user. you can also publish an external method or a python module
directly(indeed Zope is just a published python module). but sticking to
zope external methods, an example, if you had
def myhello_world(self, REQUEST):
page = " welcome to %s corner of my hello world
"%self.getParentNode().id
and just browse directly to the external method. its important to keep
in mind that stdout isn't connected to the client. the client is
connected to medusa/ZServer, which gives a channel to ZPublisher to
publish data that will be returned to the client. this mainly applies to
fs code, i'm not totally sure about the semantics of web python
methods. i know this probably goes a bit further down the rabbit hole
than you might be interested in going. if you want to know some more of
the details.
check out the medusa docs at
http://www.nightmare.com/medusa
and the ZPublisher docs under the Documentation Sec. of Zope.org.
These are dated but they give a understanding of the interaction between
medusa's asynch interfaces and zope.
and of course the source code.
you could also use document templates directly from python
def new_world_order(self, REQUEST):
from DocumentTemplate import HTML
my_sites = [('My homepage','http://homepage'),
('my favorite bookstore','http://amazon.com')
, ... etc]
page_to_return = """
<html>
<body>
<ul>
<dtml-in sites>
<li><a href="<dtml-var sequence-item>"><dtml-var sequence-key></a></li>
</dtml-in>
</ul>
</body>
</html>
"""
return HTML(my_sites)(sites=my_sites)
or evaluate a dtml file on the file system using HTMLFILE
see the DocumentTemplate directory for source and more examples
D.Templates also give you a pretty good separation of app. logic and
presentation. Doing straight python insertion in a page is not the Zope
Way. if you're interested in this type of thing, you might want to check
out some other python projects like mod_snake (apache),
pywx.sourceforge.net (aolserver), or webware. I'll think you find the
benefits of doing it through DTML offer you a lot more benefits in terms
on maintainbility and site management.
Cheers
Kapil
> > Sven Hohage wrote:
> >
> > Hallo,
> > that's the problem:
> > I've made an external method which is working with lists and should
> > return the result to Zope. The python code is working very well, but
> > is sending everything to sys.stdout( I'm using the
> > print-statement).How do I convince Zope to print the result on the
> > html-page.
> > Thanks.
>
> --
> In a world without fences, who needs gates?
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )