Log in |
Making A First Zope Websiteby Harry Henry Gebel This How-To describes the steps I went through to install Zope and create my first one page Zope web site. I used the source tarball on Linux, so if you use another operating system the installation instructions may not apply to you. I already had Python 1.5.2 installed, if you don't you will have to install it to run Zope. This How-To assumes you already know at least as much HTML as I do (ie. what the common tags mean.) The HTML 4.0 specification is a good reference if you need to know what a tag means. If you have any corrections, suggestions or answers to questions I ask in the How-To please email me. Installing ZopeAfter downloading the source tarball I installed Zope with the following commands (replace new_passwd with the password you want and change directory names to whatever would be most appropriate on your system): [hgebel@localhost hgebel]$ cd /usr/local [hgebel@localhost local]$ su [root@localhost local]# tar xvzf /home/hgebel/Zope-2.0.1-src.tgz [root@localhost local]# mv Zope-2.0.1-src Zope [root@localhost local]# chown -R nobody:nobody Zope [root@localhost local]# cd Zope [root@localhost Zope]# su nobody [nobody@localhost Zope]$ python -O w_pcgi.py [nobody@localhost Zope]$ python zpasswd.pyo -p new_passwd access [nobody@localhost Zope$ exit [root@localhost Zope]# python z2.pyo [root@localhost Zope]# exit This performed the following steps:
Logging on for the first time.Now that Zope is running you can access it by pointing your browser to http://127.0.0.1:8080 or http://localhost:8080. You should see the following screen:
Visit the link labeled Visit the management screen. You will be prompted to enter a User ID and a password. Enter superuser as the USER ID and enter the password you created above as the password. You will then see the following screen:
You may want to bookmark this screen so that you can immediately go to it in the future. The first thing we will do is create a new user for ourselves. Select the acl_users folder on the left hand frame, then press the Add button and fill out the following form:
The domain field allows you to restrict where you will be able to log into Zope from. For example, if you specified *.inet.net then no one would be able to log on as you unless they were located on the inet.net network, even if they knew you user ID and password. Roles define what permissions a user is allowed, by selecting Manager as your role you will be able to manage anything in the Zope database. You can add new roles and give each role exactly the permissions necessary to allow people with that role to perform the actions they need to perform to manage their area of the Zope database. (However, roles will not be covered further in this How-To.) When you are done filling out the form press the Add button to add this user to the database. Now we will try to log in using our new user ID. Close all your browser windows and exit your browser, then reload it. This should cause the browser to forget to log in as the Zope superuser. Now visit http://127.0.0.1:8080/manage and you will again be prompted to type in you user ID and password. This time type the new user ID and you should be able to log in successfully. (If you cannot you may have forgotten to press the Add button after filling out the above form, try logging back in as superuser and repeating the last step.) First look at DTMLNow, select the top folder in the left-hand pane of the management screen to return to the root folder. You will see that the root folder contains seven objects. An object is similar to a file except that it is located in the Zope database instead in an individual file in the computer's filesystem, and it is able to be acquired by lower levels of the database (more on this later.) There are different types of objects to represent different types of data. The type of the object is represented by the icon to the left of object's ID in the folder contents list. The Control_Panel object allows you to perform some basic maintenance of the Zope database and program, and allows you to shutdown or restart the Zope process. The QuickStart object is a folder, it is like a directory in the filesystem and holds other objects much like a directory is a file that holds other files. The acl_users object is a user folder and holds user IDs and passwords. index_html, standard_error_message, standard_html_header, and standard_html_footer are DTML Methods. A DTML Method holds DTML which is similar to the HTML used to design web pages and is in fact used by Zope to generate the HTML which will be sent to people's browsers. Select standard_error_message to get your first look at DTML.
The Id field of this form gives the name of this object. It cannot have spaces but may have underscores, capital and lower case letters, a period and numerals. Windows users note that case is significant in Zope, Standard_Error_Message would be considered a completely different object than standard_error_message. This rule applies even if you are running Zope on an operating system such as Windows that uses a filesystem where case is not significant; this is because Zope does not store object as individual files in the filesystem, but rather as object in it's own database. You cannot change the Id on this form, but you can change it be selecting the object in the folder contents list and pressing the Rename button. However, it is not a good idea to change names unnecessarily because other objects may be referring to them by their old names. The Title field contains the objects title, which is used by some objects to effect how they are rendered into HTML. For example, a DTML Method's title would be used as the title of the document when someone viewed the page that was rendered from that DTML method. An image object's title would be used to provide the ALT tag seen by non-graphical browsers. An objects title can also be used to provide you with a reminder of that object's functions if the Id is not as self-explanatory as you would like it to be. The large text entry field holds the actual DTML source code of the method. You can enter the source code directly into this box, you can cut and paste it from a text editor, you can use the Upload tab at the top of the form to upload it from a file on your filesystem, or you can use FTP to upload it to the Zope database. The last option is especially useful if you use an editor like Emacs that allows you to edit files with FTP. The Tips section of the Zope site has tips on using Zope with Emacs and XEmacs. Here are the contents of standard_error_message:
<!--#var standard_html_header-->
<!--#if error_message-->
<!--#var error_message-->
<!--#else-->
<TABLE BORDER="0" WIDTH="100%">
<TR VALIGN="TOP">
<TD WIDTH="10%" ALIGN="CENTER">
<IMG SRC="<!--#var BASE1-->/p_/ZButton" ALT="Zope">
</TD>
<TD WIDTH="90%">
<H2>Zope Error</H2>
<P>Zope has encountered an error while publishing this resource.
</P>
<P>
<STRONG>Error Type: <!--#var error_type--></STRONG><BR>
<STRONG>Error Value: <!--#var error_value--></STRONG><BR>
</P>
<HR NOSHADE>
<P>Troubleshooting Suggestions</P>
<UL>
<!--#if "error_type in ('KeyError','NameError')"-->
<LI>This resource may be trying to reference a
nonexistent object or variable <STRONG><!--#var error_value--></STRONG>.</LI>
<!--#/if-->
<LI>The URL may be incorrect.</LI>
<LI>The parameters passed to this resource may be incorrect.</LI>
<LI>A resource that this resource relies on may be encountering an error.</LI>
</UL>
<P>For more detailed information about the error, please
refer to the HTML source for this page.
</P>
<P>If the error persists please contact the site maintainer.
Thank you for your patience.
</P>
</TD></TR>
</TABLE>
<!--#comment-->
Here, events like logging and other actions may also be performed, such as
sending mail automatically to the administrator.
<!--#/comment-->
<!--#/if-->
<!--#var standard_html_footer-->
Notice that it very closely resembles HTML. The actual DTML is contained in the tags opening with <!--# and closing with -->. Anything not enclosed in one of these tags will be copied exactly into the page that is generated from the DTML. In other words, it so closely resembles HTML because it is HTML. DTML tags may also be opened with <dtml- and closed with a greater-than sign. The following two tags are equivalent: <!--#var some_dtml_method--> <dtml-var some_dtml_method> Let's look at the DTML tags used in standard__error_message one at a time. The var tag evaluates an object or expression and inserts the result into the rendered page. How the result is rendered is dependent on what type of object is being evaluated. The following tag: <!--#var standard_html_header--> evaluates the DTML method standard_html_header. When a DTML method is evaluated the resulting HTML is inserted into the current page. The methods standard_html_header and standard_html_footer contain the tags used to begin and end an HTML document. By using these two tags you not only save yourself a lot of typing, you also make it easy to propagate changes in appearance throughout your site. (More on that in a little while.) When an image object is evaluated an IMG tag is inserted into the HTML document. If you have an image object called logo, with a width of 100, a height of 50 and a title of "Our Company Logo" the following tag: <dtml-var logo>would insert the following tag into the HTML document: <img src="http://127.0.0.1:8080/logo" width="100" height="50" alt="Our Company Logo"> When an expression is evaluated the result of the expression is converted to a string and inserted in the document. Expressions are enclosed in quotes and must be valid python expressions. The following line of DTML: <P>4 + 5 = <dtml-var "4 + 5"> would appear in the generated HTML as: <P>4 + 5 = 9 The if tag is used for conditional insertion. The variable or expression referred to is evaluated, and if it is true the DTML following the tag is rendered. If it is not true and if there is an else tag following the if tag than the DTML following the else tag will be rendered. Here is a trivial example: <dtml-if "2 < 3"> <P>God is in heaven and all is right with the world. <dtml-else> <P>The law is inside out, the world is upside down. </dtml-if> <P>This will be rendered in either case If, in fact, two is lower than three, than this will be rendered as: <P>God is in heaven and all is right with the world. <P>This will be rendered in either case But if it turns out that three is lower than two then it will be rendered as: <P>The law is inside out, the world is upside down. <P>This will be rendered in either case Note that the last line, because it comes after the closing tag, is rendered unconditionally. The end tag can be expressed as either </dtml-if> or as <!--#/if-->. Here is what the DTML reference manual has to say about true and false conditions: All Zope objects are either true or false. Numeric values are true if they are non-zero and false if they are zero. Objects that are sequences of objects, like search results, are true if the sequences are non-empty and false otherwise. Most other objects are true. The comment tag is used to mark comments in the DTML code. Anything between a comment tag and the closing (</dtml-comment> or <!--#/comment-->) tag will not be rendered at all in the resulting HTML. There is much more to DTML, please read the Zope Document Template Markup Language Reference for more information. Making a new pageOkay, let's make a new page. The first thing we will do is to make a new folder to put it in. This is not necessary, you can have as many documents as you want in a folder. However, by making a new folder you will keep the root folder from getting cluttered, and we will also be able to see an example of acquisition.
Select the root folder in the left hand pane of the management screen. Find the drop down list box labeled Available Objects. Pull it down and make the selection marked Folder.
A form will come up for you to fill in with information about the folder you wish to create. The Id is the name by which the folder will be referred to. A folder is an object that contains other objects. If a folder with an Id ThatsSomeFolder contained an object with an Id SomePig.jpg that object could be referenced by pointing your browser to http://127.0.0.1:8080/ThatsSomeFolder/SomePig.jpg. If you do not specify which object in the folder you wish to reference (ie. http://127.0.0.1:8080/ThatsSomeFolder) than the object whose Id is index_html. This similar to to way some servers provide the index.html file when you point to a directory name. (But note that that is an underscore and not a period between index and html.) The Title can be used to help you remember the folders purpose if you give it an obscure Id. The Create public interface checkbox is used to denote whether this folder will be created with it's own index_html object. If you do not select this checkbox than the folder will not have it's own index_html object but will instead have to acquire it from the root folder. The way acquisition works is that if an object is requested and no object with that Id exists in the folder, Zope will start searching backwards through the folder tree until it finds an object with that Id. Since there is an object with the Id index_html in the root folder, that is the object that will be found if the new folder does not have it's own index_html object. The Create user folder checkbox is used to create a user folder in the new folder. A user folder can be used to create User Ids that are only valid for the new folder and it's subfolders. Give the new folder the Id FirstFolder, the Title My First Folder, select the Create public interface checkbox and unselect the Create user folder checkbox. When you have finished filling out the form press the Add button to create the new folder.
You should see the new folder listed in the the folder contents list. If it is not listed your browser is showing you a cached copy of the folder contents list; make sure your browser is set to compare documents to the cache every time a document is visited and not "once per session" or "never."
Select the new folder and it's contents list should appear. Let's add an image to the folder Select image from the dropdown list.
Id is the name by which this object will be referred. Title is the string that will appear in the image's ALT tag. Image is the file on your filesystem which will be uploaded to Zope. Give the image the Id FirstImage, the title First Image, and use the browse button to select any image on your filesystem that is of a type your browser can view. Press the Add button and the image will be uploaded to Zope. Note that we did not include an extension in the Id. Because the period has a special meaning to python, Using Ids with periods in them is a little more complicated than using Ids without periods. For more on using Id's with periods see the DTML section of the ZDP's Zope FAQ. Now, select index_html. This object is a DTML Document, for the purposes of this How-To a DTML Document and DTML method are equivalent. Here is the DTML code for index_html: <!--#var standard_html_header--> <h2><!--#var title_or_id--></h2> <p> This is the <!--#var id--> Document. </p> <!--#var standard_html_footer--> The standard_html_header and standard_html_footer objects are DTML methods that contain the that contain the HTML headers and footers. Because FirstFolder does not contain objects with these Ids they are acquired from the root folder. The id variable is a property that evaluates to a string containing the Id of the current document. The title_or_id variable is a property that evaluates to a string containing the title of the current document unless the title is empty, in which case it evaluates to the current document's Id. Select the View tap located at the top of the right hand pane to view the page that will be generated from this DTML. Now push your browsers back button to return to the DTML entry form and change the document's title to My First Document, then change the document's code to read as follows: <!--#var standard_html_header--> <P>This is my first DTML document. <P><dtml-var FirstImage> <!--#var standard_html_footer--> By selecting the Change button at the bottom of the form you will update the Zope database with index_html's new contents. Now point your browser to http://127.0.0.1/FirstFolder and you should see something like this:
Congratulations! You've made you're first Zope website. I know this ends abruptly, but I'm not sure what the best area to cover next is, not least because I am just learning Zope myself. I would appreciate any feedback on what needs improvement in this document and where it should go next. |