Home arrow Zope arrow Page 4 - Creating Zope Products

Finishing Touches - Zope

The arrangement of Zope objects required for a large website can get somewhat messy and end up looking disorganized. Fortunately, you can use the plethora of Zope Products available to give you a hand, or you can create your own, if there are none that perfectly suit your needs. This article shows you how easy it is to create a Zope Product.

  1. Creating Zope Products
  2. The Stuffing
  3. Inner Mechanisms
  4. Finishing Touches
By: Peyton McCullough
Rating: starstarstarstarstar / 15
March 07, 2006

print this article



Though the person.py file is complete, Zope still will not acknowledge our new Zope Product. This is because there is a bit more work left to do. We have to tell Zope exactly where our Zope Product is located and how to go about adding the Product—what methods are required to create the Product and what-not.

Thankfully, though, this is a pretty simple process. Zope looks around in the Products directory for __init__.py files. These files contain instructions on what Zope should do to add the particular Product with which the file is associated. Go ahead and create a file named __init__.py and place it in the directory with the person.py file.

import person

def initialize(context):
  "Instructions for creating an object."
  context.registerClass(person.Person, constructors =

If you followed everything closely, then you should now be ready to test out the Product we created. Simply restart Zope and select our new Product from the drop-down list in the Zope Management Interface.

There is one additional thing I would like to explain. Though generating all the required HTML in the Python of a Product is perfectly possible, it's not completely practical. A better solution might be to create DTML files and then return those to the user instead. We'll modify our person.py file. The first thing you need to do is import Globals:

import Globals


Next, you need to add an attribute to Person and assign it to the DTML page. We'll use the page dtml_page.dtml here:


   dtml_page = Globals.HTMLFile('dtml_page', globals())


Finally, we must create the DTML page. Put it in the same directory as person.py and name it dtml_page.dtml (even though we don't use the extension in Globals.HTMLFile, the extension is required):

      <title><dtml-var title></title>
      This is a DTML page for <dtml-var title>.


From here, there are a lot of paths you can take. Try experimenting with Zope Products a bit more and familiarizing yourself with them. Simple ones aren't difficult to create, as this article has illustrated with the Person Product. You can use them to simplify complex logic that can't be organized using traditional methods. I know that many Python scripters feel that creating numerous Zope objects and attempting to force them to interact is a bit cumbersome, but Zope Products can get around this as well.

Of course, this article only explains a very small fraction of the inner workings of Zope Products. Products are pretty complex creatures that allow much more customization and functionality than a simple article like this can explain. However, I do hope that this article has introduced you to the very basics of Products so that you can decide where to go next.

>>> More Zope Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Creating Zope Products
- Plone Content Types With Archetypes
- Flat User Management in Zope
- Creating Basic Zope Applications
- Getting started with Zope for Linux and Sola...
- ZPT Basics (part 4)
- ZPT Basics (part 3)
- ZPT Basics (part 2)
- ZPT Basics (part 1)
- Exception Handling In DTML
- DTML Basics (part 4)
- DTML Basics (part 3)
- DTML Basics (part 2)
- DTML Basics (part 1)
- Using Zope With Apache

Developer Shed Affiliates


Dev Shed Tutorial Topics: