Google App Engine in 40 minutes (the absolute essentials)
Upcoming SlideShare
Loading in...5
×
 

Google App Engine in 40 minutes (the absolute essentials)

on

  • 637 views

This talk covers just the stuff needed to get you up-to-speed with Google App Engine and its associated technologies (based on the Python run-time, of course). In addition to a bit of talking, Paul ...

This talk covers just the stuff needed to get you up-to-speed with Google App Engine and its associated technologies (based on the Python run-time, of course). In addition to a bit of talking, Paul will also demo a working webapp built and deployed on the App Engine cloud... all in 40 minutes.

Statistics

Views

Total Views
637
Slideshare-icon Views on SlideShare
637
Embed Views
0

Actions

Likes
1
Downloads
12
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Google App Engine in 40 minutes (the absolute essentials) Google App Engine in 40 minutes (the absolute essentials) Presentation Transcript

    • Google App Engine in 40 Minutes (The Absolute Essentials) Paul Barry – Institute of Technology, Carlow in Ireland PyCon Ireland 2011 2
    • Grab the slides:http://paulbarry.itcarlow.ie/GAE.pdf
    • 4
    • 5
    • The Absolute Essentials in 40 Minutes... 6
    • What is Google App Engine? 7
    • Cloud-based Application Deployment Environment 8
    • Integrated Collection of Google APIs 9
    • Guidos Playground 10
    • Is App Engine “just another framework”? 11
    • It is all about your data... 12
    • Think of App Engine as a highly scalable,distributed database server that you can program with Python 2.5... 13
    • Think of App Engine as a highly scalable,distributed database server that you can program with Python 2.5... and (cough) Java and (cough, cough) Go 14
    • MVC 15
    • Lets solve a real problem... 16
    • 17
    • 18
    • 19
    • 20
    • Step 1 Download the SDK from: http://code.google.com/appengine/and sign-up for an App Engine account ID 21
    • Step 2Create a new project... 22
    • ...by creating an app.yaml file application: dwwgapp version: 1 runtime: python api_version: 1 handlers: - url: /static static_dir: static - url: /.* script: dwwgapp.py 23
    • Step 3Model Your Data 24
    • Create dwwgDB.py (1 of 3)from google.appengine.ext import db 25
    • Create dwwgDB.py (2 of 3)from google.appengine.ext import dbclass Sighting(db.Model): 26
    • 27
    • Create dwwgDB.py (3 of 3)from google.appengine.ext import dbclass Sighting(db.Model): name = db.StringProperty() email = db.StringProperty() date = db.DateProperty() time = db.TimeProperty() location = db.StringProperty() fin_type = db.StringProperty() whale_type = db.StringProperty() blow_type = db.StringProperty() wave_type = db.StringProperty() 28
    • Step 4Define your UI in HTML 29
    • The header.html template<html> <head> <title>{{ title }}</title> </head> <body> <h1>{{ title }}</h1> 30
    • The footer.html template <p> {{ links }} </p> </body></html> 31
    • The form_start.html template<form method=”POST” action=”/”> <table> 32
    • The form_end.html <tr><th>&nbsp;</th> <td><input type="submit" value="{{ sub_title }}"></td> </tr> </table></form> 33
    • Render some HTMLfrom google.appengine.ext.webapp import templatehtml = template.render(templates/header.html, {title: Report a Possible Sighting}) 34
    • Rendering a Pagefrom google.appengine.ext.webapp import templatehtml = template.render(templates/header.html, {title: Report a Possible Sighting})html = html + template.render(templates/form_start.html, {})# Do something in here to render the form?!?!?!?!?!?!?html = html + template.render(templates/form_end.html, {sub_title: Submit Sighting})html = html + template.render(templates/footer.html, {links: }) 35
    • Step 5Write code to render your form 36
    • Django Forms to the Rescue!from google.appengine.ext.db import djangoformsimport dwwgDBclass SightingForm(djangoforms.ModelForm): class Meta: model = dwwgDB.Sighting 37
    • Rendering a Page, Againfrom google.appengine.ext.webapp import templatehtml = template.render(templates/header.html, {title: Report a Possible Sighting})html = html + template.render(templates/form_start.html, {})html = html + str(SightingForm())html = html + template.render(templates/form_end.html, {sub_title: Submit Sighting})html = html + template.render(templates/footer.html, {links: }) 38
    • Step 6Tie it all together with logic 39
    • You need to start your webappfrom google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_app …app = webapp.WSGIApplication([(/.*, SightingInputPage)], debug=True)def main(): run_wsgi_app(app)if __name__ == __main__: main() 40
    • Remember the app.yaml file? application: dwwgapp version: 1 runtime: python api_version: 1 handlers: - url: /static static_dir: static - url: /.* script: dwwgapp.py 41
    • Put this code in dwwgapp.pyfrom google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_app …app = webapp.WSGIApplication([(/.*, SightingInputPage)], debug=True)def main(): run_wsgi_app(app)if __name__ == __main__: main() 42
    • Whats this SightingInputPage thing? 43
    • Responding to a GET Requestclass SightingInputPage(webapp.RequestHandler): def get(self): html = template.render(templates/header.html, {title: Report a Possible Sighting}) html = html + template.render(templates/form_start.html, {}) html = html + str(SightingForm()) html = html + template.render(templates/form_end.html, {sub_title: Submit Sighting}) html = html + template.render(templates/footer.html, {links: }) self.response.out.write(html) 44
    • Step 7Take your local app for a spin 45
    • Click the “Run” button... or$ dev_appserver.py dwwgapp 46
    • Ta Da! :-( 47
    • Looks kinda shitty, doesnt it? 48
    • Add a little CSS goodness..<link type="text/css" rel="stylesheet" href="/static/dwwg.css" /><link type="text/css" rel="stylesheet" href="/static/styledform.css" /> 49
    • ...and some code to dwwgDB.py_FINS = [Falcate, Triangular, Rounded]_WHALES = [Humpback, Orca, Blue, Killer, Beluga, Fin, Gray, Sperm]_BLOWS = [Tall, Bushy, Dense]_WAVES = [Flat, Small, Moderate, Large, Breaking, High] ...location = db.StringProperty(multiline=True)fin_type = db.StringProperty(choices=_FINS)whale_type = db.StringProperty(choices=_WHALES)blow_type = db.StringProperty(choices=_BLOWS)wave_type = db.StringProperty(choices=_WAVES) 50
    • Ta Da! :-) 51
    • Step 8Do something with your data 52
    • You need to POST data! POST data with put() 53
    • class SightingInputPage(webapp.RequestHandler): def get(self): html = template.render(templates/header.html, {title: Report a Possible Sighting}) html = html + template.render(templates/form_start.html, {}) html = html + str(SightingForm()) html = html + template.render(templates/form_end.html, {sub_title: Submit Sighting}) html = html + template.render(templates/footer.html, {links: }) self.response.out.write(html) 54
    • class SightingInputPage(webapp.RequestHandler): def get(self): html = template.render(templates/header.html, {title: Report a Possible Sighting}) html = html + template.render(templates/form_start.html, {}) html = html + str(SightingForm()) html = html + template.render(templates/form_end.html, {sub_title: Submit Sighting}) html = html + template.render(templates/footer.html, {links: }) self.response.out.write(html) def post(self): 55
    • class SightingInputPage(webapp.RequestHandler): def get(self): html = template.render(templates/header.html, {title: Report a Possible Sighting}) html = html + template.render(templates/form_start.html, {}) html = html + str(SightingForm()) html = html + template.render(templates/form_end.html, {sub_title: Submit Sighting}) html = html + template.render(templates/footer.html, {links: }) self.response.out.write(html) def post(self): new_sighting = dwwgDB.Sighting() 56
    • class SightingInputPage(webapp.RequestHandler): def get(self): html = template.render(templates/header.html, {title: Report a Possible Sighting}) html = html + template.render(templates/form_start.html, {}) html = html + str(SightingForm()) html = html + template.render(templates/form_end.html, {sub_title: Submit Sighting}) html = html + template.render(templates/footer.html, {links: }) self.response.out.write(html) def post(self): new_sighting = dwwgDB.Sighting() new_sighting.name = self.request.get(name) new_sighting.email = self.request.get(email) new_sighting.date = self.request.get(date) new_sighting.time = self.request.get(time) new_sighting.location = self.request.get(location) new_sighting.fin_type = self.request.get(fin_type) new_sighting.whale_type = self.request.get(whale_type) new_sighting.blow_type =self.request.get(blow_type) new_sighting.wave_type = self.request.get(wave_type) 57
    • class SightingInputPage(webapp.RequestHandler): def get(self): html = template.render(templates/header.html, {title: Report a Possible Sighting}) html = html + template.render(templates/form_start.html, {}) html = html + str(SightingForm()) html = html + template.render(templates/form_end.html, {sub_title: Submit Sighting}) html = html + template.render(templates/footer.html, {links: }) self.response.out.write(html) def post(self): new_sighting = dwwgDB.Sighting() new_sighting.name = self.request.get(name) new_sighting.email = self.request.get(email) new_sighting.date = self.request.get(date) new_sighting.time = self.request.get(time) new_sighting.location = self.request.get(location) new_sighting.fin_type = self.request.get(fin_type) new_sighting.whale_type = self.request.get(whale_type) new_sighting.blow_type =self.request.get(blow_type) new_sighting.wave_type = self.request.get(wave_type) new_sighting.put() 58
    • And dont forget to say “Thanks!”html = template.render(templates/header.html, {title: Thank you!})html = html + "<p>Thank you for providing your sighting data.</p>"html = html + template.render(templates/footer.html, {links: Enter <a href="/">another sighting</a>.})self.response.out.write(html) 59
    • 60
    • Step 9Deploy to Googles cloud 61
    • Click the “Deploy” button... or$ appcfg.py upload dwwgapp/ 62
    • http://dwwgapp.appspot.com 63
    • Step 10Realise your not done... 64
    • Damn That Spam!Some smart-alec posted a sightingof a Great White Shark on the top of Mount Leinster... 65
    • What to do? 66
    • A tiny config tweak to app.yaml... application: dwwgapp version: 1 runtime: python api_version: 1 handlers: - url: /static static_dir: static - url: /.* script: dwwgapp.py login: required 67
    • ...and two tiny code changes Add this to the dwwgDB.py model: which_user = db.UserProperty()Add this to your post() method in dwwgapp.py:new_sighting.which_user = users.get_current_user() 68
    • http://dwwgapp.appspot.com 69
    • http://appengine.google.com 70
    • And after all that,what do you end up with? 71
    • Happy Clients! 72
    • Want to learn moreabout this talks example code? 73
    • Head First Python 74
    • Dont forget to check outthe App Engine Tutorial on Sunday with Seán Murphy 75
    • 76