Created
August 31, 2010 19:14
-
-
Save GeorgeNava/559553 to your computer and use it in GitHub Desktop.
Basic application handler in python for App Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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