Friday, April 15, 2011

Source Code For Uploading Static Files to Google App Engine

1. Source code for app.yaml

 application:  version: 1 runtime: python api_version: 1  handlers: - url: /(.*\.(gif|png|jpg|ico|js|css))   static_files: \1   upload: (.*\.(gif|png|jpg|ico|js|css))  - url: .*   script: main.py

2. Source code for main.py

 import os from google.appengine.ext import webapp from google.appengine.ext.webapp import util from google.appengine.ext.webapp import template  class MainHandler(webapp.RequestHandler):   def get (self, q):     if q is None:       q = 'index.html'      path = os.path.join (os.path.dirname (__file__), q)     self.response.headers ['Content-Type'] = 'text/html'     self.response.out.write (template.render (path, {}))  def main ():   application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)   util.run_wsgi_app (application)  if __name__ == '__main__':   main ()


For Further Reading,

0 comments:

Post a Comment