04 – Google App Engine for Python – Validation & Sessions

A simple validation and how to keep values in the session.

appengine_config.py

[crayon lang="python"]
from gaesessions import SessionMiddleware

def webapp_add_wsgi_middleware(app):
app = SessionMiddleware(app, cookie_key = ‘You must change this’)
return app
[/crayon ]

main.py

[crayon lang="python"]
from gaesessions import get_current_session

class MainHandler(webapp2.RequestHandler):
def get(self):
session = get_current_session()
count = session.get(‘count’, 0)
session['count'] = count + 1
self.response.out.write(html % session['count'])

def post(self):
firstName = self.request.get(‘firstName’)
familyName = self.request.get(‘lastName’)
if len(firstName) < 2 or len(familyName) < 2:
self.redirect(‘/’)
self.response.out.write(‘First Name: ‘ + firstName
+ ‘ Family Name: ‘ + familyName)

app = webapp2.WSGIApplication([('/', MainHandler)], debug = True)
[/crayon]

1 comment to 04 – Google App Engine for Python – Validation & Sessions

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>