Skip to content

Instantly share code, notes, and snippets.

@GeorgeNava
Created August 31, 2010 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeorgeNava/559553 to your computer and use it in GitHub Desktop.
Save GeorgeNava/559553 to your computer and use it in GitHub Desktop.
Basic application handler in python for App Engine
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
# We extend 'webapp.RequestHandler' to reduce excess code
class request(webapp.RequestHandler):
# I hate typing, make it shorter
def write(self,text):
self.response.out.write(text)
# The less typing the better
def render(self,view,data=None):
if not '.' in view: view=view+'.html'
path=os.path.join(os.path.dirname(__file__),'views',view)
html=template.render(path,data)
self.response.out.write(html)
# pass 'urls' as string or list of tuples like [(route1,control1),(route2,control2),...]
def run(route,main=None):
if isinstance(route,list): controller=route
else: controller=[(route,main)]
run_wsgi_app(webapp.WSGIApplication(controller,debug=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment