ZopeGuideQuickstart

Quickstart

Installation

The only dependency for Zope 3 installation is Python 2.4. Zope 3 can be installed in all major platforms from source, and binary packages are also available for Windows. Major GNU/Linux distributions include Zope 3.

GNU/Linux

Download Zope 3.3 from http://www.zope.org/Products/Zope3 . Make sure you have already installed Python 2.4.3 or later, but Python 2.5 is not supported.

To install (as root):

# tar zxvf Zope-3.3.0.tgz
# cd Zope-3.3.0
# ./configure --with-python=/path/to/python2.4
# make install

Replace /path/to/python2.4 with path to your Python interpreter. If you installed Python using ./configure;make;make install your Python path will be /usr/local/bin/python2.4 .

Windows

The best method for installing Zope 3 in Windows is using the executable installer.

Make an instance

Zope 3 uses instances to contain the information relevant to a server (or a set of servers). To create an instance go to the installation directory (On Windows you will find this command in \path\to\python\Scripts\) and run the mkzopeinstance command, it will ask for a few values. It will look like something like this:

$ cd /usr/local/Zope-3.3.0/bin/
$ ./mkzopeinstance
Please choose a directory in which you'd like to install Zope
'instance home' files such as database files, configuration files,
etc.

Directory: /home/admin/myzope

Please choose a username for the initial administrator account.
This is required to allow Zope's management interface to be used.

Username: admin

Please select a password manager which will be used for encode the password of
the initial administrator account.

 1. Plain Text
 2. MD5
 3. SHA1

Password Manager Number [1]: 2
'MD5' password manager selected

Please provide a password for the initial administrator account.

Password:
Verify password:

After creating the instance go to instance home, then run zope:

$ cd /home/admin/myzope
$ ./bin/runzope

You should see something like this:

------
2006-03-13T08:20:12 INFO root -- HTTP:localhost:8080 Server started.
        Hostname: localhost
        Port: 8080
------
2006-03-13T08:20:12 INFO root Startup time: 9.746 sec real, 5.660 sec CPU

If you get a port error, check whether port 8080 is already used by other programs. For the time being, just stop it and run zope again.

The instance home

Now look into your instance home, first read the README.txt. This instance home can be considered as your workplace.

$ ls * -F
README.txt

bin:
debugzope*        i18nmergeall*      importchecker*      runzope*        test.bat*
debugzope.bat*    i18nmergeall.bat*  importchecker.bat*  runzope.bat*    zopectl*
i18nextract*      i18nstats*         pyskel*             static-apidoc*  zopeservice.py*
i18nextract.bat*  i18nstats.bat*     pyskel.bat*         test*           zpasswd*

etc:
ftesting.zcml            package-includes/             securitypolicy.zcml  ssh_host_rsa_key
overrides_ftesting.zcml  principals.zcml               server.pem           zdaemon.conf
overrides.zcml           securitypolicy-ftesting.zcml  site.zcml            zope.conf

lib:
python/

log:
access.log  README.txt  z3.log

var:
Data.fs  Data.fs.index  Data.fs.lock  Data.fs.tmp  README.txt

As you can see, the bin directory contains a few scripts like runzope, test etc. Some scripts are only specific to Windows. Zope saves all data in directory var. Backup this directory regularly. If Data.fs is missing, it is automatically re-created when you run zope again. In etc you can find some configuration files. In etc/zope.conf you can edit port numbers of various servers. In lib/python you can place your Zope3 packages. By default this won't be in your Python path. You can also place your packages in any standard Python path.

The ZMI

If you open a web browser and go to http://localhost:8080 you'll see the ZMI (Zope Management Interface).

Go ahead and click the Login link at the upper right. Enter the user name and password you gave when creating the instance. Now click on [top]? under Navigation on the right. Play around with adding some content objects (the Zope 3 name for instances that are visible in the ZMI). Note how content objects can be arranged in a hierarchy by adding "folders" which are special content objects that can hold other content objects.

There is nothing special about the ZMI, it is just the default skin for Zope 3. You can modify it to your liking, or replace it entirely.

When you're done exploring with the ZMI, go back to the window where you typed runzope and see that each request from your browser was displayed there as it happened. Press Control-C to stop Zope.

Hello World

This section narrate the steps to create a hello word application. First get into your Zope 3 instance and make a package there.

$ cd /home/admin/myzope/lib/python
$ mkdir hello
$ cd hello
$ touch __init__.py

All python code could as well go in '__init__.py'. But to follow the convention create another module. For larger projects create browser package and for tiny apps browser.py is enough.

$ touch browser.py

Now a configuration file to register the hello package. Edit /home/admin/myzope/etc/package-includes/hello-configure.zcml and the following lines there:

<configure
    xmlns="http://namespaces.zope.org/zope">

  <include package="hello" />

</configure>

Now write this python code in browser.py:

from zope.publisher.browser import BrowserView

class HelloView(BrowserView):

    def __call__(self):
        return """
        <html>
        <head>
          <title>Hello World</title>
        </head>
        <body>
          Hello World
        </body>
        </html>
        """

Finally, write a configuration file for your new package to register the view, configure.zcml, belonging in your package directory (lib/python/hello). This registers a page view with the name hello, with publics permission and using the Python class HelloView:

<configure
    xmlns="http://namespaces.zope.org/browser">

    <page
        for="*"
        name="hello"
        permission="zope.Public"
        class=".browser.HelloView"
    />

</configure>

Start Zope 3 (/home/admin/myzope/bin/runzope). To see the application working, visit: http://localhost:8080/hello

... --Janos, Sat, 01 Mar 2008 22:18:16 +0000 reply

Pls note, as a newbie I struggled why the runzope.bat did not run the second time. Switched on the echo in the batch file and finally noticed the traceback problem that gave the error message. When fixed the error zope was running again. Janos Simon



( 97 subscribers )