title: My first Google App Engine/Python app
body: <p>I am trying to write my first GAE/Python application that does the following three things:</p>
  
  <ol>
  <li>Displays a form where the user can enter details about themself (index.html)</li>
  <li>Stores the submitted form data in the datastore</li>
  <li>Retrieves all data from datastore and displays all results above the form (index.html)</li>
  </ol>
  
  <p>However, I'm getting the following error</p>
  
  <blockquote>
    <p>line 15, in MainPage 'people' : people NameError: name 'people' is not
    defined</p>
  </blockquote>
  
  <p>Any advice on how to resolve this and get my app working will be appreciated!</p>
  
  <p><strong>main.py</strong></p>
  
  <pre><code>import webapp2
  import jinja2
  import os
  
  jinja_environment = jinja2.Environment(
      loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
  
  class MainPage(webapp2.RequestHandler):
      def get(self):
  
          people_query = Person.all()
          people = people_query.fetch(10)
  
      template_values = {
          'people': people
      }
  
      template = jinja_environment.get_template('index.html')
      self.response.out.write(template.render(template_values))
  
  # retrieve the submitted form data and store in datastore   
  class PeopleStore(webapp2.RequestHandler):
      def post(self):
          person = Person()
          person.first_name = self.request.get('first_name')
          person.last_name = self.request.get('last_name')
          person.city = self.request.get('city')
          person.birth_year = self.request.get('birth_year')
          person.birth_year = self.request.get('height')
          person.put()        
  
  # models a person class 
  class Person(db.Model):
      first_name = db.StringProperty()
      last_name = db.StringProperty()
      city = db.StringProperty()
      birth_year = db.IntegerProperty()
      height = db.IntegerProperty()
  
  
  app = webapp2.WSGIApplication([('/', MainPage),
                                  ('/new_person')], debug=True)
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          {% for person in people %}
              {% if person %}
                  &lt;b&gt;{{ person.first_name }}&lt;/b&gt; 
                  &lt;b&gt;{{ person.last_name }}&lt;/b&gt;
                  &lt;b&gt;{{ person.city }}&lt;/b&gt; 
                  &lt;b&gt;{{ person.birth_year }}&lt;/b&gt; 
                  &lt;b&gt;{{ person.height }}&lt;/b&gt; 
                  &lt;hr&gt;&lt;/hr&gt;
              {% else %}
                  No people found         
          {% endfor %}
  
          &lt;form action="/new_person" method="post"&gt;           
              &lt;div&gt;&lt;textarea name="first_name" rows="3" cols="60"&gt;&lt;/textarea&gt;&lt;/div&gt;
              &lt;div&gt;&lt;textarea name="last_name" rows="3" cols="60"&gt;&lt;/textarea&gt;&lt;/div&gt;
              &lt;div&gt;&lt;textarea name="city" rows="3" cols="60"&gt;&lt;/textarea&gt;&lt;/div&gt;
              &lt;div&gt;&lt;textarea name="birth_year" rows="3" cols="60"&gt;&lt;/textarea&gt;&lt;/div&gt;
              &lt;div&gt;&lt;textarea name="height" rows="3" cols="60"&gt;&lt;/textarea&gt;&lt;/div&gt;
              &lt;div&gt;&lt;input type="submit" value="Submit"&gt;&lt;/div&gt;
          &lt;/form&gt;         
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>app.yaml</strong></p>
  
  <pre><code>application: some_name
  version: 1
  runtime: python27
  api_version: 1
  threadsafe: true
  
  handlers:
  - url: /.*
    script: main.app
  
  libraries:
  - name: jinja2
    version: latest
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 1</strong>
  *<em>main.py</em>*</p>
  
  <pre><code>import webapp2
  import jinja2
  import os
  
  from google.appengine.ext import db
  
  jinja_environment = jinja2.Environment(
      loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
  
  class MainPage(webapp2.RequestHandler):
      def get(self):
  
          people_query = Person.all()
          people = people_query.fetch(10)
  
          template_values = {
              'people': people
          }
  
          template = jinja_environment.get_template('index.html')
          self.response.out.write(template.render(template_values))
  
  
  class PeopleStore(webapp2.RequestHandler):
      def post(self):
          person = Person()
          person.first_name = self.request.get('first_name')
          person.last_name = self.request.get('last_name')
          person.city = self.request.get('city')
          person.birth_year = self.request.get('birth_year')
          person.height = self.request.get('height')
          person.put()        
  
  
  class Person(db.Model):
      first_name = db.StringProperty()
      last_name = db.StringProperty()
      city = db.StringProperty()
      birth_year = db.IntegerProperty()
      height = db.IntegerProperty()
  
  
  app = webapp2.WSGIApplication([('/', MainPage),
                                  ('/new_person')], debug=True)
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 2</strong>
  *<em>main.py</em>*</p>
  
  <p>The following edit fixed this error</p>
  
  <blockquote>
    <p>AttributeError: 'str' object has no attribute 'get_match_routes'</p>
  </blockquote>
  
  <pre><code>app = webapp2.WSGIApplication([('/', MainPage),('/new_person',PeopleStore)], debug=True)
  </code></pre>
  
  <p>Ok great, the form displays in the browser, but when I submit the data, I get this error:</p>
  
  <blockquote>
    <p>BadValueError: Property birth_year must be an int or long, not a
    unicode</p>
  </blockquote>
  
  <hr>
  
  <p><strong>EDIT 3
  main.py</strong></p>
  
  <pre><code>person.birth_year = int(self.request.get('birth_year'))
  person.height = int(self.request.get('height'))
  </code></pre>
  
  <p>resolved this error:</p>
  
  <blockquote>
    <p>badvalueerror property must be an int or long, not a unicode</p>
  </blockquote>
  
  <p>Ok, good so far. The data stores in the data store. However, my page comes up blank...</p>