[Zope] mixing python and DTML is hellish!

kosh@aesaeion.com kosh@aesaeion.com
Thu, 28 Feb 2002 22:47:19 -0700 (MST)


On Thu, 28 Feb 2002, Roy Mathew wrote:

>
> Folks,
>
> I have been trying out Zope, and am now getting beyond the trivial.
> I do have a question about python vs DTML.
>
> What I am finding is that mixing and matching python scripts and DTML
> (methods and documents) is rather hellish/confusing. For example:

I would certainly agree that mixing and matching DTML with python script
is a bad idea however I also think that is the wrong way to do things. I
used to mix and match items and over time found that it did not work very
well for many reasons. What I have been doing for about 9 months or so is
putting just about all logic in python and then using DTML to present it
only. So I have lots of little scripts and then just use dtml-var to call
them. This works very well and is maintainable.

> >  o descending into python and then back up to DTML is hard, when you
>    are trying to use acquisition. The python code does not understand
>    contexts and acquisition in quite the same way as DTML.

Could you be more precise in how they you see the python code as not
seeing contexts and acquistion in the same way that DTML does? Python
scripts allow for a fair bit of power by allowing you to specify exactly
what it is you want to do.

>
>  o I am trying to use the SQL Session object from within a python
>    script, and am having all kinds of difficulty.
>

This part I can't help with since I don't tend to do anything with SQL.

> I am starting to believe that it is cleaner (although not as powerful)
> to use DTML exclusively (and python only for that which is impossible
> in DTML). This' kind of saddens me as the "Zope Book" suggests that
> python is highly interchangeable with, and more powerful than DTML.
>

Overall I would recommend going to python almost exclusively instead of
DTML. Then just use the simplest DTML constructs needed to render the
output from python.

> Am I totally off base? Is there some valuable reading that I have missed?
> How do experienced ZOPErs view this issue?
>

I think you are making the mistake of using DTML to put the logic in and
since you have been doing that for a while it seems easier. However if you
know python or take the time to learn it fairly well then you will find
the making python scripts is usually a lot faster then making DTML code
and easier to maintain.

Also check out irc.openprojects.net #zope there are often those around
that can help depending on what time of day you ask for help.

Overall I like DTML a lot since it allows you to seperate a page into many
little objects that know how to behave in various situations. I find this
makes it very easy to plug things together to build complex solutions.
However DTML is for presentation not for logic so put the logic in python
code where it fits better.