Last active
December 31, 2015 04:29
-
-
Save jimmykane/7934112 to your computer and use it in GitHub Desktop.
App engine python Boiler Main
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
''' | |
@author: Dimitrios Kanellopoulos | |
@contact: [email protected] | |
''' | |
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