App Engine by default uses django, a Python web framework that’s a bit like Rails or CakePHP, most of the tutorial on the App Engine Documentation would not teach you to use Templates except the main Using Templates part. While this tutorial is good, it would not teach you how have a more optimized version. Here is how i did, i suggest you to read the App Engine Using Templates Tutorial:

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
def page_display(page,file,values={}):
template_values = {}
template_values.update(values)
try:
template_values.update(page.template_values)
except:
pass
path = os.path.join(os.path.dirname(__file__),file)
page.response.out.write(template.render(path,template_values))
class MainPage(webapp.RequestHandler):
def get(self,page):
self.template_values = {
"message" : "Hello World",
"message2" : "Hello"
}
page_display(self,"templates/index.html")
def main():
application = webapp.WSGIApplication(
[
('/', MainPage)
],
debug = True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == “__main__”:
main()

As you can see if you have a lot of classes it would be a easier to remember and use
page_display(self,"templates/index.html")
then
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))

Share and Enjoy:
  • Digg
  • Reddit
  • Slashdot
  • del.icio.us
  • StumbleUpon
  • TwitThis
  • Fark
  • Facebook
  • Technorati
  • Sphinn
  • Furl
  • Google
  • Mixx