Download presentation
Presentation is loading. Please wait.
Published byMaria Wilkins Modified over 9 years ago
1
Cloud computing lectures: Programming with Google App Engine Keke Chen
2
Outline Using google app engine - walk through a simple example
3
Background: how cgi works Request : content/url sent by the client Response: content return to the client’s browser 3 Client server Request: request a url, click a button, etc Request a url: “get” url Response: CGI returns some html code Click buttons: “post” something
4
Python “hello world” CGI program helloworld.py print 'Content-Type: text/plain' print '' print 'Hello, world!'
5
Preparation Have your gmail account Installing google apps tool – dev_appserver.py, the development web server dev_appserver.py – appcfg.py, for uploading your app to App Engine appcfg.py
6
Setup the development env Windows/mac: check http://code.google.com/appengine/download s.html to find the package http://code.google.com/appengine/download s.html Nimbus17: already installed at /usr/local/gae
7
Webapp does Wraps the CGI functions – API for handling request/response Python Web Server Gateway Interface (WSGI) – A framework for developing CGI programs with Python 7
8
from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class MainPage(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp World!') application = webapp.WSGIApplication( [('/', MainPage)], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main()
9
Configuration file app.yaml – A standard file format for configuration – A set of API designed to access the configuration – http://www.yaml.org/ http://www.yaml.org/ – Don’t need to know much about yaml – Check GAE’s typical configurations 9
10
App.yaml application: helloworld version: 1 runtime: python27 threadsafe: false api_version: 1 handlers: - url: /.* script: helloworld.py If threadsafe is set to true, use helloworld.application
11
Start development server How to start /usr/local/gae/dev_appserver.py helloworld/ -p port -a address
12
Use users service Use the google account service 12
13
Using users service user = users.get_current_user() if user: self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, ' + user.nickname()) else: self.redirect(users.create_login_url(self.request.uri))
14
Handling forms with webapp self.response.out.write(""" """)
16
db - datastore db.Model GQL: sql like query language greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10") Or omit select *: greetings = Greeting.gql("ORDER BY date DESC LIMIT 10") With parameters: greetings = Greeting.gql("WHERE author = :1 ORDER BY date DESC",users.get_current_user()) greetings = Greeting.all() greetings.filter("author =", users.get_current_user()) greetings.order("-date") 16
17
Entity group Passing parameters
19
Use templates Templates are used to generate the similar webpages with different variables 19
21
Use stylesheet Change app.yaml Include the code for using stylesheet
22
Upload application Create an application at Google AppEngine Change the app name in app.yaml correspondingly Run appcfg.py update helloworld/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.