Section 5.4. Tying Everything Together

5.4. Tying Everything Together

Because we're redirecting everybody to the index method, we probably ought to create one. So, here goes:

<body>     <h2><a href="/list_by_category">Bookmarks by Category</a></h2>     <h2><a href="/list">All Bookmarks</a></h2>     <h2><a href="/bookmarks/add">Add New Link</a></h2> </body>

This is just plain HTML, but it uses the bookmark, list, and list_by_categories URLs that we defined earlier. Before we finish things off, we really need to add a link to each of our bookmarks in the /list page that will allow a user to edit that bookmark:

<body>   <ul>     <li py:for="bookmark in bookmarks">          <a href="${}">            <span py:replace="bookmark.bookmarkName">Link to Bookmark</span>          </a>            -- <span py:replace="bookmark.description">Description of the Bookmark               goes here. </span>              <br />              <a href="${'/bookmark/edit/'+str(}">edit</a> --              <b> Categories: </b>              <span py:for="cat in bookmark.categories">               ${cat.categoryName}              </span>              <hr width="300" align="left"/>        </li>   </ul> </body>

In this little template, we have a loop for each bookmark in the database, and an inner loop for each category attached to that bookmark. This gives us a nice listing of the bookmark name and description, along with a link to the edit page for that specific bookmark. All of this is followed by a list of the categories that bookmark is related to.

Rapid Web Applications with TurboGears(c) Using Python to Create Ajax-Powered Sites
Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites
ISBN: 0132433885
EAN: 2147483647
Year: 2006
Pages: 202

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: