Skip navigation

google app engine

index.py

class Person( db.Model ) :
  name = db.StringProperty()
  
class TPerson( webapp.RequestHandler ) :
  def get( self ) :
    
    # run once
    '''
    people = [ 'John Hopkins', 'Bob Jordan', 'Mike Bobs' ]
    
    for person in people :
      p = Person()
      p.name = person
      p.put()
    '''
    
    people = db.GqlQuery( 'select * from Person' ).fetch( 1000 ) 
    
    # if you don't .fetch(), then the addition of dynamic
    # properties won't work here.
    for person in people :
      person.shortname = person.name[ 0:2 ]
    
    self.response.out.write( template.render( 'TPerson.html', { 'people' : people } ) )

application = webapp.WSGIApplication([
  
  ( '/TPerson', TPerson ),
  
  ], debug=True )



def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()

TPerson.html

{% for p in people %}
<p>{{ p.name }}</p>
<p>{{ p.shortname }}</p>
{% endfor %}
Advertisements

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

%d bloggers like this: