[Checkins] SVN: grok/trunk/doc/ Adjust tutorial to changes in
grokproject.
Martijn Faassen
faassen at infrae.com
Mon Mar 19 17:56:08 EDT 2007
Log message for revision 73360:
Adjust tutorial to changes in grokproject.
Changed:
U grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app.py
A grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app_templates/
A grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app_templates/index.pt
U grok/trunk/doc/tutorial.txt
-=-
Modified: grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app.py
===================================================================
--- grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app.py 2007-03-19 21:02:20 UTC (rev 73359)
+++ grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app.py 2007-03-19 21:56:06 UTC (rev 73360)
@@ -1,4 +1,7 @@
import grok
-
-class Sample(grok.Application, grok.Container):
+
+class testproj(grok.Application, grok.Container):
pass
+
+class Index(grok.View):
+ pass # see app_templates/index.pt
\ No newline at end of file
Added: grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app_templates/index.pt
===================================================================
--- grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app_templates/index.pt 2007-03-19 21:02:20 UTC (rev 73359)
+++ grok/trunk/doc/groktut/an_empty_grok_project/src/sample/app_templates/index.pt 2007-03-19 21:56:06 UTC (rev 73360)
@@ -0,0 +1,10 @@
+<html>
+<head>
+</head>
+<body>
+ <h1>Congratulations!</h1>
+
+ <p>Your Grok application is up and running.
+ Edit <code>sample/app_templates/index.pt</code> to change
+ this page.</p>
+</body>
Modified: grok/trunk/doc/tutorial.txt
===================================================================
--- grok/trunk/doc/tutorial.txt 2007-03-19 21:02:20 UTC (rev 73359)
+++ grok/trunk/doc/tutorial.txt 2007-03-19 21:56:06 UTC (rev 73360)
@@ -163,14 +163,36 @@
This first pops up a login dialog (username: ``grok`` and password:
``grok``). It will then show a simple Grok admin interface. This
-allows you to install new Grok applications. Our sample application
-(``sample.app.Sample``) will be available for adding. After adding
-it, we can click on the link and see Grok's welcome message.
+allows you to install new Grok applications.
+Our sample application (``sample.app.Sample``) will be available for
+adding. Let's try this out. Go to the Grok admin page:
+
+ http://localhost:8080
+
+and add a Sample application. Give it the name ``test``.
+
+You can now go to the installed application if you click on its link. This
+will bring you to the following URL:
+
+ http://localhost:8080/test
+
+You should see a simple web page with the following text on it::
+
+ Congratulations!
+
+ Your Grok application is up and running. Edit
+ sample/app_templates/index.pt to change this page.
+
You can shut down Zope 3 at any time by hitting ``CTRL-c``. Shut it
down now. We will be shutting down and starting up Zope 3 often in
this tutorial.
+Practice restarting Zope now, as you'll end up doing it a lot during
+this tutorial. It's just stopping Zope and starting it again:
+`CTRL-c`` and then ``parts/instance/bin/zopectl fg`` from your Sample
+project directory.
+
An empty Grok project
---------------------
@@ -209,15 +231,25 @@
.. include:: groktut/an_empty_grok_project/src/sample/app.py
:literal:
-Not very much yet, but enough to make an installable Grok
-application. We'll go into the details of what this means later.
+Not very much yet, but enough to make an installable Grok application
+and display its welcome page. We'll go into the details of what this
+means later.
Besides this, there is an empty ``__init__.py`` file to make this
-directory a Python package.
+directory a Python package.
+There is also a directory called ``app_templates``. It contains a single
+template called ``index.pt``:
+
+.. include:: groktut/an_empty_grok_project/src/sample/app_templates/index.pt
+ :literal:
+
+This is the template for your project's welcome page.
+
What's left is a ``configure.zcml`` file. Unlike in typical Zope 3
applications, this will only ever contain a single line that registers
-this application with Zope 3 which means we can completely ignore it:
+this application with Zope 3. This means we can typically completely
+ignore it, but we'll show it here once for good measure:
.. include:: groktut/an_empty_grok_project/src/sample/configure.zcml
:literal:
@@ -232,19 +264,19 @@
a web application we need to be able to put some simple HTML on the
web, first.
-As you might've seen previously, our ``Sample`` application has a
-stock front page. Let's change that.
+As you saw previously, our ``Sample`` application has a stock front
+page, generated by grokproject. Let's change that.
To do this, go to the ``app_templates`` directory in ``src/sample/``.
-This directory contains the HTML used for anything defined in the
+This directory contains the templates used for anything defined in the
``app`` module. Grok knows to associate the directory to the module by
its name (``<module_name>_templates``).
In this directory we will edit the ``index`` template for our
``Sample`` application object. To do this, open the ``index.pt`` file
in a text editor. The ``.pt`` extension indicates that this file is a
-Zope Page Template (ZPT). This allows us to make the page dynamic
-later on.
+Zope Page Template (ZPT). We're just going to put HTML in it now, but
+this allows us to make page dynamic later on.
Change the ``index.pt`` file to contain the following (very
simplistic) HTML:
@@ -252,35 +284,31 @@
.. include:: groktut/publishing_a_simple_web_page/src/sample/app_templates/index.pt
:literal:
-Let's try this out. Restart Zope (``CTRL-c`` and then
-``parts/instance/bin/zopectl fg`` from your Sample project
-directory). If you haven't yet created a sample application object, go
-to the Grok admin page:
+Then reload the page:
- http://localhost:8080
+ http://localhost:8080/test
-and add a Sample application. Give it the name ``test``.
+You should now see the following text::
-You can now go to the installed application if you click on its link. This
-will bring you to the following URL:
+ Hello world!
- http://localhost:8080/test
+Note that you can change templates and see the effects instantly:
+there is no need to restart Zope to see the effect. This is not true
+for changes on the Python level, for instance when you add a
+template. We show an example of this next.
-You should see a simple web page with the following text on it::
- Hello world!
-
A second view
-------------
-Since our view is named `index` we've done something slightly special:
-it's the default view of our application object. We can also still
+Our view is named ``index``. This in fact means something slightly
+special: it's the default view of our application object. We can also
access it explicitly by naming the view:
http://localhost:8080/test/index
If you view that URL in your browser, you should see the same result
-as before.
+as before. This is the way all other, non-index views are accessed.
Often, your application needs more than one view. A document for
instance may have an ``index`` view that displays it, but another
@@ -302,12 +330,17 @@
view named ``bye`` for the application, just like the ``Index`` class
that was already created for us indicates that we want a view named
``index``. A *view* is a way to view some content, in this case
-installations of our ``Sample`` application.
+installations of our ``Sample`` application. Note that the view name
+in the URL is always going to be lowercase, while the class name
+normally starts with an uppercase letter.
The empty class definition above is enough for Grok to go look in the
-``app_templates`` directory for ``bye.pt``.
+``app_templates`` directory for ``bye.pt``. The rule is that a the
+template should have the same name as the class, but lowercased and
+with the ``.pt`` postfix.
-Restart Zope again. You can now go to a new web page called ``bye``:
+Restart Zope (``CTRL-C, then ``parts/instance/bin/zopectl fg``). You
+can now go to a new web page called ``bye``:
http://localhost:8080/test/bye
@@ -316,9 +349,6 @@
Bye world!
-The rule for each view is that your template should have the same name
-as the class, but lowercased and with the ``.pt`` postfix.
-
Making our page dynamic
-----------------------
More information about the Checkins
mailing list