Step 9: List Form Pathway

There is a form in the template for creating lists. There is a method in the CreateList handler for handling HTTP POST, and creating a list.

Next I need to generate the List form, when the user clicks the "Create a List" link. Here's CreateList.get again, unchanged:

class CreateList(webapp.RequestHandler): def get(self): template_values = { 'list_form': 1 } self.response.out.write(render(template_values))

... and the matching form inside the template, turned on by the list_form switch:

{% if list_form %} <form action="/create_list/" method="post"> <textarea style="background:#eeee00" name="name" rows=1 cols=33> </textarea><br> <span align="left"> <input type="Submit" name="button" value="Create list"> </span> <span style="padding-left:138px"> <a href="/">cancel</a></span> <br> </form> {% else %} <br> <a href="/list_form/">Create a List</a><br><br> {% endif %}

Then, I need CreateList.post to receive this POST, and create a list:

def post(self): list = List() list.name = self.request.get('name') list.put() self.redirect("/")