Lists and Items‎ > ‎

Step 11: Item Form Pathway

< Previous Step Conclusion >

There is a form in the template for creating items. There is a method in the CreateItem handler for handling HTTP POST, and creating an item.

I'll need to GET an Item form, making sure it has the list key. Again, CreateItem.get, unchanged:

class CreateItem(webapp.RequestHandler):
  def get(self, list_key):
     template_values = {
        'item_form': 1,
        'list_key': list_key

... and its matching template section:

{% if item_form %}
  {% ifequal list.key list_key %}
    <a name="form"></a>
    <form action="/create_item/" method="post">
      <span style="padding-left:15px">
         <textarea style="background:#eeee00" name="name" 
               rows=1 cols=33>
      <span style="padding-left:15px"> 
         <input type="Submit" name="button" value="Create item">
      <span style="padding-left:130px">
         <a href="/">cancel</a>
      <input type="hidden" name="list_key" 
                               value="{{ list_key }}">
  {% else %}
    <span style="padding-left:15px">
       <a href="/item_form/{{ list.key }}/#form">
            Create an item
  {% endifequal %}
{% else %}

We'll instantiate Items in the handler:

  def post(self):
    item = Item()

    item.list_key = self.request.get('list_key') = self.request.get('name')