Skip to main content

Code for Uploading Static Files to Google App Engine


All the magic behind hosting websites with Google App Engine are two files –  app.yaml and main.py - that are responsible for all the magic. 

With app.yaml, Share a list of files with Google App Engine SDK that should be uploaded only while main.py file handles the HTTP requests when serving the website.


1. Source code for app.yaml
application: (application name)
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 ()

In our example, we are putting all the static files like images, CSS, html, etc. in the root folder but you may also organize them as sub-directories and the app.yaml file should be updated according.

Popular posts from this blog

Add Smilies/ Emoticons in Google Talk (Gtalk)

I Really love to use Smilies while chatting. Well, unfortunately GTalk doesn’t have smilies included by default . So Here You will find Out How To do it ... Well, it’s really simple. The main concept of getting smilies is through converting the text smilies of GTalk into smilies. As the new Version of GTalk includes support for themes we can add a theme with custom smilies in order to get rid of those text smilies. In short, it’s nothing but just adding a custom theme. Follow Simple Steps : 1) Download any one of the below smiley theme which you like. Download Classic Emoticons theme Download Bubble Emoticons theme 2) Now extract the zip to a specific folder. 3) Go to the following location: C:/Documents and Settings/(your user name)/Local Settings/Application Data/Google/Google Talk/themes/user/chat 4) Replace (your user name) with your Windows account user name without brackets The folder chat isn’t there by default so you have to create a folder with the name “chat” inside t...

Create a PDF Viewer ShortCode

Do you need to show PDF files on your WordPress Blog. If yes here is a small code for this. This will gives a feature to open the PDF files using Google Docs . The first step is to paste the following code into your functions.php file: function pdflink($attr, $content) { return '<a class="pdf" href="http://docs.google.com/viewer?url='  . $attr['href'] . '">'.$content.'</a>'; } add_shortcode('pdf', 'pdflink'); Once you saved the file, you'll be able to use the shortcode on your posts and page. Here is the syntax : [pdf href="http://yoursite.com/linktoyour/file.pdf"]View PDF[/pdf]   If you enjoyed this post, Please Consider Sharing it! You may also like to read: How to turn off Find My iPhone How to fix 'iPhone is disabled Connect to iTunes' error messages How to mirror/screencast iPhone to a smart TV how to Delete All Photos from iPhone How to make Chrome default browser How ...

Google Translate, Now With Voice Input

Google Chrome 11 added support for HTML speech input API. " With this API, developers can give web apps the ability to transcribe your voice to text. When a web page uses this feature, you simply click on an icon and then speak into your computer's microphone. The recorded audio is sent to speech servers for transcription, after which the text is typed out for you." Google Translate is the first Google service that uses this feature. If you use Google Chrome 11 Beta , Google Chrome 12 Dev / Canary or a recent Chromium build and visit Google Translate (Click Here) , you can click the voice input icon. Right now, this feature only works for English, so you need to select "English" from the list of input languages.