Google App Engine 入門課程 國網中心格網技術組 專案助理研究員 鄭宗碩 , Zong-shuo Jheng [email_address] 參考網頁 : http://nchc-gae.blogspot.com
Outline  <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot  </li></ul><ul><li>Hello Goog...
What is Google App Engine <ul><li>Hosting services on Google cloud platform </li></ul><ul><li>Benefited by Google File Sys...
Outline  <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot  </li></ul><ul><li>Hello Goog...
Prerequirements for a new pilot  <ul><li>Python runtime </li></ul><ul><ul><li>http://python.org/ </li></ul></ul><ul><li>Go...
Outline  <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot  </li></ul><ul><li>Hello Goog...
Hello Google App Engine! NCHC, Google App Engine experience course. 2009 << hello.py >> from google.appengine.ext import w...
Outline  <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot  </li></ul><ul><li>Hello Goog...
Pieces of a flying GAE <ul><li>Configuration files </li></ul><ul><li>MVC design pattern </li></ul><ul><li>webapp framework...
Configuration files <ul><li>app.yaml </li></ul><ul><li>cron.yaml </li></ul><ul><li>index.yaml </li></ul>NCHC, Google App E...
MVC design pattern NCHC, Google App Engine experience course. 2009 <<Template>> from google.appengine.ext.webapp  import t...
webapp framework NCHC, Google App Engine experience course. 2009 << hello.py >> from google.appengine.ext import webapp fr...
Template NCHC, Google App Engine experience course. 2009 <<index.py>> import os from google.appengine.ext.webapp import te...
Google User service API NCHC, Google App Engine experience course. 2009 from google.appengine.api import  users class Main...
Dashboard NCHC, Google App Engine experience course. 2009
Outline  <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot  </li></ul><ul><li>Hello Goog...
Data-storing black box - Google DataStore <ul><li>Types and Property Classes </li></ul><ul><li>http://code.google.com/intl...
Data-storing black box - Google DataStore <ul><li>Creating and Deleting Data </li></ul><ul><li>Getting data </li></ul>NCHC...
Data-storing black box - Google DataStore NCHC, Google App Engine experience course. 2009 query = db.GqlQuery(&quot;SELECT...
Upcoming SlideShare
Loading in...5
×

Gae

1,386

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,386
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Gae

  1. 1. Google App Engine 入門課程 國網中心格網技術組 專案助理研究員 鄭宗碩 , Zong-shuo Jheng [email_address] 參考網頁 : http://nchc-gae.blogspot.com
  2. 2. Outline <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot </li></ul><ul><li>Hello Google App Engine! </li></ul><ul><li>Pieces of a flying GAE </li></ul><ul><li>Data-storing black box - Google DataStore </li></ul>NCHC, Google App Engine experience course. 2009
  3. 3. What is Google App Engine <ul><li>Hosting services on Google cloud platform </li></ul><ul><li>Benefited by Google File System, BigTable </li></ul><ul><li>Free for limited accessing </li></ul><ul><li>(10 free Web AP, up to 500MB of storage, up to 5 million page views a month, 2 billion CPU clock cycles one day) </li></ul>NCHC, Google App Engine experience course. 2009
  4. 4. Outline <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot </li></ul><ul><li>Hello Google App Engine! </li></ul><ul><li>Pieces of a flying GAE </li></ul><ul><li>Data-storing black box - Google DataStore </li></ul>NCHC, Google App Engine experience course. 2009
  5. 5. Prerequirements for a new pilot <ul><li>Python runtime </li></ul><ul><ul><li>http://python.org/ </li></ul></ul><ul><li>Google App Engine SDK </li></ul><ul><ul><li>http://code.google.com/appengine/ </li></ul></ul><ul><ul><li>~/:> upzip google_appengine_1.2.2.zip </li></ul></ul><ul><ul><li>appcfg.py, dev_appserver.py </li></ul></ul><ul><li>Eclipse with PyDev </li></ul><ul><ul><ul><li>http://nchc-gae.blogspot.com/2009/05/eclipse-pydev-google-app-engine.html </li></ul></ul></ul><ul><li>Applying for a free account </li></ul><ul><ul><ul><li>http://nchc-gae.blogspot.com/2009/05/google-app-engine.html </li></ul></ul></ul>NCHC, Google App Engine experience course. 2009
  6. 6. Outline <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot </li></ul><ul><li>Hello Google App Engine! </li></ul><ul><li>Pieces of a flying GAE </li></ul><ul><li>Storing data in Google DataStore </li></ul>NCHC, Google App Engine experience course. 2009
  7. 7. Hello Google App Engine! NCHC, Google App Engine experience course. 2009 << hello.py >> 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/html; charset=UTF-8' self.response.out.write(&quot;Hello Google App Engine!&quot;) application = webapp.WSGIApplication([('/', MainPage)], debug=True) def main(): run_wsgi_app(application) if __name__ == &quot;__main__&quot;: main() <<app.yaml>> application: hello-gae version: 1 runtime: python api_version: 1 handlers: - url: /.* script: hello.py
  8. 8. Outline <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot </li></ul><ul><li>Hello Google App Engine! </li></ul><ul><li>Pieces of a flying GAE </li></ul><ul><li>Data-storing black box - Google DataStore </li></ul>NCHC, Google App Engine experience course. 2009
  9. 9. Pieces of a flying GAE <ul><li>Configuration files </li></ul><ul><li>MVC design pattern </li></ul><ul><li>webapp framework </li></ul><ul><li>Template </li></ul><ul><li>Google User service API </li></ul><ul><li>Dashboard </li></ul>NCHC, Google App Engine experience course. 2009
  10. 10. Configuration files <ul><li>app.yaml </li></ul><ul><li>cron.yaml </li></ul><ul><li>index.yaml </li></ul>NCHC, Google App Engine experience course. 2009
  11. 11. MVC design pattern NCHC, Google App Engine experience course. 2009 <<Template>> from google.appengine.ext.webapp  import template <<DataStore>> from google.appengine.ext import db <<User-defined Handler class>> Eg. class Main_handler(webapp.RequestHandler)
  12. 12. webapp framework NCHC, Google App Engine experience course. 2009 << hello.py >> 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/html; charset=UTF-8' self .response.out.write (&quot;Hello Google App Engine!&quot;) application = webapp.WSGIApplication ([('/' , MainPage)], debug=True) def main(): run_wsgi_app (application) if __name__ == &quot;__main__&quot;: main() 1 2 3 1 2 3
  13. 13. Template NCHC, Google App Engine experience course. 2009 <<index.py>> import os from google.appengine.ext.webapp import template class MainPage(webapp.RequestHandler):    def get(self):      template_value = { 'Welcome_msg': 'Hello, Template!' }      path = os.path.join(os.path.dirname(__file__),'template/index.htm')      outstr = template.render (path, template_value)      self.response.out.write(outstr) <<template/index.htm>> <html> <head><title>Hello Template</title></head> <body> {{ Welcome_msg }} </body> </html> <ul><ul><ul><li>Reference : http://nchc-gae.blogspot.com/2009/05/google-app-engine-template-tutorial.html </li></ul></ul></ul>
  14. 14. Google User service API NCHC, Google App Engine experience course. 2009 from google.appengine.api import users class MainPage(webapp.RequestHandler):   def get(self):     user = users.get_current_user()     if user :       greeting = (&quot;Welcome, %s! (<a href=&quot;%s&quot;>sign out</a>)&quot; %                   ( user.nickname() , users.create_logout_url( &quot;/&quot; ) ))     else:       greeting = (&quot;<a href=&quot;%s&quot;>Sign in or register</a>.&quot; %                   users.create_login_url( &quot;/&quot; ) )     self.response.out.write(&quot;<html><body>%s</body></html>&quot; % greeting) user = users.get_current_user() if user :   print &quot;Welcome, %s!&quot; % user.nickname()   if users.is_current_user_admin() :     print &quot;<a href=&quot;/admin/&quot;>Go to admin area</a>&quot; User class: email nickname() email() user_id() create_login_url(dest_url) create_logout_url(dest_url) get_current_user() is_current_user_admin()
  15. 15. Dashboard NCHC, Google App Engine experience course. 2009
  16. 16. Outline <ul><li>What is Google App Engine </li></ul><ul><li>Prerequirements for a new pilot </li></ul><ul><li>Hello Google App Engine! </li></ul><ul><li>Pieces of a flying GAE </li></ul><ul><li>Data-storing black box - Google DataStore </li></ul>NCHC, Google App Engine experience course. 2009
  17. 17. Data-storing black box - Google DataStore <ul><li>Types and Property Classes </li></ul><ul><li>http://code.google.com/intl/en/appengine/docs/python/datastore/typesandpropertyclasses.html </li></ul><ul><li>Entity and Model </li></ul>NCHC, Google App Engine experience course. 2009 from google.appengine.ext import db class Beverage(db.Model): name = db.StringProperty(required=True) price = db.IntegerProperty(required=True) sugar = db.StringProperty(required=True,choices=set([&quot;full&quot;,&quot;half&quot;,&quot;none&quot;])) ice = db.BooleanProperty(default=True) tea = Beverage(name=“Green Tea&quot;, price=20, sugar=&quot;half&quot;) tea.ice=False
  18. 18. Data-storing black box - Google DataStore <ul><li>Creating and Deleting Data </li></ul><ul><li>Getting data </li></ul>NCHC, Google App Engine experience course. 2009 pet.put() / db.put(pet), pet.delete() / db.delete(pet) class Story(db.Model):   title = db.StringProperty()   date = db.DateTimeProperty() query = Story.all() query.filter('title =', 'Foo') query.order('-date') query.ancestor(key) query.filter('title =', 'Foo').order('-date').ancestor(key)
  19. 19. Data-storing black box - Google DataStore NCHC, Google App Engine experience course. 2009 query = db.GqlQuery(&quot;SELECT * FROM Story WHERE title = :1 &quot; &quot;AND ANCESTOR IS :2 &quot; &quot;ORDER BY date DESC&quot;, 'Foo', key) query = Story.gql(&quot;WHERE title = :title &quot; &quot;AND ANCESTOR IS :parent &quot; &quot;ORDER BY date DESC&quot;, title='Foo', parent=key)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×