We use Zope related software throughout our day at GateHouse Media. Specifically, we run a hosted solution, Zope4Media provided by Zope Corporation. Our level of involvement with the software on the development end of things is strictly limited to template development in ZPT.
We also build a lot of other generic web applications separate from our Zope4Media installations. Naturally, it makes sense for us to investigate the use of Zope 3 for use as our primary development environment for these other applications.
UPDATE: Aaron Lehmann of Zope Corporation was kind enough to respond to many of the points I make in this post. I've added his responses inline below.
What is Zope 3?Zope 3 is the latest in the line of Zope-powered web application servers. It was released nearly 4 years ago on November 6th, 2004. It is a standalone server written in the excellent Python programming language that provides a framework for developing applications such as content management systems, intranets, and other dynamic web-based tools. It provides data storage in the form of the ZODB (Zope Object Database) which operates as transparent and persistent storage of Python objects.
Zope 3, like other modern development platforms, follows a loose interpretation of the MVC (Model-View-Controller) design pattern. By nature of it being a Python application, it encourages clean and intelligently designed code.
The purpose of this blog post is to journey through the installation, configuration and development of a simple Zope 3 web application.
InstallationFirst things first, we need to download and install Zope 3. It must be installed and configured on the server before you may begin development.
Since I'm a Subversion junkie, I want to grab a checkout of the Zope 3 application, rather than download.
Head over to the Zope 3 website and look for their SVN repository. There's a link in the left sidebar for Zope SVN, so that's probably a good place to start. This page, however, doesn't seem to have any information on where the SVN repo lives, so we hit up the SVN FAQ. The first thing I see on this page is:
svn co svn://svn.zope.org/repos/main/Zope/trunk Zope
That looks to be exactly what we're after, so I go ahead and try to checkout. Unfortunately, this appears to checkout Zope 2, not Zope 3. There's also no indiciation on their FAQ that this is or isn't the case.
I'll save you the headache of trying to figure out just where Zope 3 lives on their repository, since it's not really documented anywhere. The SVN list of Zope 3 releases really lives here:
svn ls svn://svn.zope.org/repos/main/Zope3/tags
From there, you'll see a list of Zope 3 releases. We're interested in the latest release, which from what I can see from here, is 3.3.1. We grab that release by checking out with the following:
svn co svn://svn.zope.org/repos/main/Zope3/tags/3.3.1/ zope
The checkout will take a while. After it's finished, it looks like the entire checkout clocks in at around 111 MB. Quite large.
Now that we've got the latest version of Zope 3 in our hands, we need to install it on our system. Here's where I picked up Benji York's excellent Zope 3 quick start guide.
Following from Benji's tutorial, I run the installation command for Linux, since I'm on OS X:
python setup.py install_data --install-dir .
All went well with installation, so now's time to setup our first instance of Zope 3 (a standalone application):
python zope/bin/mkzopeinstance
The initial instances weighs in at 376k.
Running the serverOur Zope instances makes available to us the Zope 3 application server to host our instance. We do so with the following command from within the instance path:
bin/runzope
Your Zope 3 application should be accessible at http://localhost:8080.
At this point, I'll be completely honest with you. I wrote this tutorial in segments, meaning I wrote down my initial steps first, then iterate on the instructions and comments to increase accuracy. However, the second time around, when trying to run the server for the application I had already built, I got the following error:
ImportError: No module named zope.app.twisted.main
Now, I am completely certain I had a working application when I last touched it. That said, I decided to start fresh with the instructions above. I checked out a fresh copy of Zope 3, reinstalled, and attempted to create a new instance. This is what I get when trying to run 'mkzopeinstance':
ImportError: No module named _zope_proxy_proxy
I honestly have no clue what's going on here. I'm beginning to think the SVN location above is incorrect, but there is absolutely no (good) information on Zope.org to point me in the right direction. Even the official 3.3.1 release page has no reference of the SVN location.
Unfortunately, the list of releases in the Zope 3 SVN project makes it quite hard to figure out what release is correct:
3.2.2/ 3.2.3/ 3.3.0/ 3.3.0-zope.interface/ 3.3.0b2/ 3.3.0c1/ 3.3.1/ 3.3.2/ 3.4.0a1/ 3.4.0b1/ 3.4.0b2/ 3.4.0c1/ Zope-3.1.0/ Zope-3.1.0b1/ Zope-3.1.0c1/ Zope-3.1.0c2/ Zope-3.1.0c3/ Zope-3.2.0/ Zope-3.2.0b1/ Zope-3.2.0b2/ Zope-3.2.0b3/ Zope-3.2.1/ Zope-3.3.0b1/ Zope3-29921/
Naturally, '3.3.1/' appears to be (the most) correct.
Anyway, I'm going to continue with the tutorial assuming you finally got it working, somehow.
Zope Management Interface (ZMI)The Zope Management Interface is the default interface you see when accessing your application for the first time. It goes without saying that this interface is incredibly intimidating to those who are using Zope 3 for the first time. Even after working with the interface a bit, I'm still not sure exactly what everything does, and why everything is there.
That said, I'm sure everything is there for a reason. It'd be nice to have a more formal beginners documentation regarding exactly what everything in the ZMI does.
My biggest pet peeve with ZMI is that there's no way to log out of the application. I can successfully login using the credentials I provided when creating the instance, but there is no logout link anywhere. After a few tries at guessing what the logout URL might be, it turns out that it is:
http://localhost:8080/logout.html
That should come in handy.
Zope Object Database (ZODB)As mentioned, Zope 3 stores data using the ZODB. From Wikipedia:
Essentially, this means data is read and written from the database transparently through the use of Python objects, which also means there is no need for SQL. Unfortunately, this also means data portability is somewhat affected, since it's not as easy to import or extract data from ZODB (at least, not apparently).
Applications have static pages, so the first thing on our list is to serve a static page with our new Zope 3 application. Should be fairly straightforward.
At this point, I'll turn over the mic to Benji, where he can walk you through the quick steps of how to get a static page up and running.
The basic steps are:
The steps are quite simple, but it's not entirely apparent how exactly everything works. The most confusing part of the whole thing is the XML-based configuration files. In my opinion, using XML to manage the configuration for these objects rather than native Python configuration objects is not necessary. This is a hot topic in the Zope 3 community.
After I created the object using Benji's suggestions, I found that I had to somehow 'enable' the object. This is done by selecting the object from the left menu and then naming the object.
When working with changes to your code, it should be noted that you need to restart the Zope 3 application server to reflect the new code.
Templating in Zope 3 is accomplished with Zope Page Templates (ZPT), an XML-based templating system designed specifically for use with Zope. A simple example:
<div tal:attributes="class here/class; style string:border: 1px solid black;" tal:content="string:Hello World!"> Hello World! </div>
I'm very familiar with ZPT, since all of the template development work we do with Zope4Media is done with ZPT. Zope Corporation owns and maintains Zope4Media, which is based on Zope 3.
While ZPT is fairly straightforward and easy to learn, it presents several problems.
From what I understand, one of the major benefits to using ZPT is that it is XML-based, meaning WYSIWYG HTML editors should be able to render and modify the code without messing with the logic. That said, no professional template developer uses a WYSIWYG editor, in any fashion.
At some point in your application, you're going to break something, I promise. It's certainly useful to have a strong debug tool for development, but Zope 3 appears to be lacking in this area. When you break something in Zope 3, you may see an error page something like this:
A system error has occurred.
This is great for production, since you don't necessarily want retail users to see the innards of your code. In development, however, it's not useful at all. I understand there may be ways to display the full traceback to the retail page, but I'm not entirely sure how.
While Zope 3 has long since been a viable option for developers looking for rapid MVC-style development framework, I don't necessarily agree with some of the approaches the platform takes on templating (ZPT) and data handling (ZODB).
I've come up with a few bullet points highlighting what I see are the pros and cons of Zope 3:
Pros
Post new comment