A Simple Project Management Tool With TurboGears – Templates

We have created our models, created our controller actions and forms. Now we are going to set up our templates. Let’s take a look at the controller action “new_project”:


@expose('ideas.templates.new_project')
def new_project(self):
    """ Displays the project form. """
    return dict(project_form=project_form)

In this action, we tell TurboGears that when new_project action is called, we are going to render it with “new_project.mak” file in the “templates” folder. We also pass “project_form” variable to the template.

Let’s create our templates. This is the content of new_project.mak:

<!-- ideas/templates/new_project.mak -->
<%inherit file="local:templates.master"/>

<%def name="title()">Project Form</%def>

${project_form()|n}

This is the content of new_task.mak:

<!-- ideas/templates/new_task.mak -->
<%inherit file="local:templates.master"/>

<%def name="title()">Task Form</%def>

${task_form()|n}

And this is the content of show_project.mak:

<!-- ideas/templates/show_project.mak -->
<%inherit file="local:templates.master"/>

<%def name="title()">${project.project_name}</%def>

<h1>${project.project_name}</h1>
<div>${project.project_description}</div>

<h2>Tasks</h2>
<ul>
    % for task in tasks:
        <li>${task.task_name}</li>
    % endfor 
</ul>

Now start your web server and visit “http://127.0.0.1:8080/new_project” and see how the project creation form looks like:

Project Creation Form

And let’s head to task creation page at “http://127.0.0.1:8080/new_task“:

Task Creation Form

Go ahead and play with it. Do something yourself. For more on the templates you can visit mako documentation.

About these ads
This entry was posted in Mako, Python, Templates, TurboGears and tagged , , , , , , . Bookmark the permalink.

One Response to A Simple Project Management Tool With TurboGears – Templates

  1. Pingback: A Simple Project Management Tool With TurboGears – Setting Up the Forms | TurboGears Notes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s