Skip to content

Instantly share code, notes, and snippets.

@jimmykane
Last active December 31, 2015 04:29
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 jimmykane/7934112 to your computer and use it in GitHub Desktop.
Save jimmykane/7934112 to your computer and use it in GitHub Desktop.
App engine python Boiler Main
'''
@author: Dimitrios Kanellopoulos
@contact: jimmykane9@gmail.com
'''
import os
import logging
import webapp2
import jinja2
from google.appengine.ext import blobstore
template_env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.getcwd()))
class MainPageHandler(webapp2.RequestHandler):
def get(self):
# Do your stuff here
pass
class UploadFormHandler(webapp2.RequestHandler):
def get(self):
upload_url = blobstore.create_upload_url('/upload/')
template = template_env.get_template('blob.html')
context = {
'upload_url': upload_url
}
self.response.write(template.render(context))
class UploadFormHandler(webapp2.RequestHandler):
def post(self):
blobs = self.get_uploads('upload')
# So some logging here and concept to store the reference of the blob key.
#self.redirect('/')
app = webapp2.WSGIApplication([
# Essential handlers
("/", MainPageHandler),
("/upload/", UploadFormHandler),
('/upload/picture/', PictureUploadHandler),
],debug=True)
# Extra Hanlder like 404 500 etc
def handle_404(request, response, exception):
logging.exception(exception)
response.write('Oops! Naughty Mr. Jiggles (This is a 404)')
response.set_status(404)
app.error_handlers[404] = handle_404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment