Building the Game Itself
At this point we’ve got a pretty good collection of models to help manage the back-end logic of this game. Now let’s move on to the game itself and start building some realtime user interactions.
User Authentication
The models.py file contains a good deal of the code needed to run the core of this game, but we still have to build the views and start assembling the controller classes to actually interact with the user. We’ll be using a single file to handle all of the controller functionality, whether the request originates from an HTTP request, an XMPP request, or even an SMS message. Inside your appengine folder, create a file called main.py and add the following code:
# standard python library stuff import wsgiref.handlers import os, logging, random, urllib, cgi, re from datetime import datetime # app engine imports from google.appengine.ext.webapp import template from google.appengine.ext import webapp, db from google.appengine.api import xmpp, users, urlfetch from google.appengine.ext.webapp.util import login_required from django.utils import simplejson as json # import all models: from models import * def main(): # setup the specific URL handlers application = webapp.WSGIApplication([('/', MainHandler), ], debug=True) # run the application wsgiref.handlers.CGIHandler().run(application) # handle the root URL for the site class MainHandler(webapp.RequestHandler): def get(self): # load the current user from google current_user = users.get_current_user() # ...
Get Building the Realtime User Experience now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.