20081012 gae intro

1,316 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,316
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

20081012 gae intro

  1. 1. A Simple Glance Say Hello To The World An Unfinished Blog System An Intro to GAE Hu Zi Ming hzmangel@gmail.com Oct 12, 2008 An Intro to GAE 1 / 30
  2. 2. A Simple Glance Say Hello To The World An Unfinished Blog System Outline 1 A Simple Glance What is GAE Benefits And Limitations 2 Say Hello To The World 3 An Unfinished Blog System An Intro to GAE 2 / 30
  3. 3. A Simple Glance Say Hello To The World An Unfinished Blog System What is GAE The abbreviation for Google App Engine An Intro to GAE 3 / 30
  4. 4. A Simple Glance Say Hello To The World An Unfinished Blog System What is GAE The abbreviation for Google App Engine Providing hosting services An Intro to GAE 3 / 30
  5. 5. A Simple Glance Say Hello To The World An Unfinished Blog System What is GAE The abbreviation for Google App Engine Providing hosting services Generally speaking, it is FREE An Intro to GAE 3 / 30
  6. 6. A Simple Glance Say Hello To The World An Unfinished Blog System What is GAE The abbreviation for Google App Engine Providing hosting services Generally speaking, it is FREE Support python only current now An Intro to GAE 3 / 30
  7. 7. A Simple Glance Say Hello To The World An Unfinished Blog System Benefits FREE at most time An Intro to GAE 4 / 30
  8. 8. A Simple Glance Say Hello To The World An Unfinished Blog System Benefits FREE at most time Pay for what you have used An Intro to GAE 4 / 30
  9. 9. A Simple Glance Say Hello To The World An Unfinished Blog System Benefits FREE at most time Pay for what you have used Integrated with some other google services An Intro to GAE 4 / 30
  10. 10. A Simple Glance Say Hello To The World An Unfinished Blog System Benefits FREE at most time Pay for what you have used Integrated with some other google services Scalable storage and computation power An Intro to GAE 4 / 30
  11. 11. A Simple Glance Say Hello To The World An Unfinished Blog System Limitations Thread and crontab are forbidden An Intro to GAE 5 / 30
  12. 12. A Simple Glance Say Hello To The World An Unfinished Blog System Limitations Thread and crontab are forbidden Limited socket feature An Intro to GAE 5 / 30
  13. 13. A Simple Glance Say Hello To The World An Unfinished Blog System Limitations Thread and crontab are forbidden Limited socket feature Limitation of resources(CPU, memory, bandwidth...) An Intro to GAE 5 / 30
  14. 14. A Simple Glance Say Hello To The World An Unfinished Blog System Limitations Thread and crontab are forbidden Limited socket feature Limitation of resources(CPU, memory, bandwidth...) No access to the filesystem An Intro to GAE 5 / 30
  15. 15. A Simple Glance Say Hello To The World An Unfinished Blog System Limitations Thread and crontab are forbidden Limited socket feature Limitation of resources(CPU, memory, bandwidth...) No access to the filesystem Data can only be exported as csv file An Intro to GAE 5 / 30
  16. 16. A Simple Glance Say Hello To The World An Unfinished Blog System Limitations Thread and crontab are forbidden Limited socket feature Limitation of resources(CPU, memory, bandwidth...) No access to the filesystem Data can only be exported as csv file No way to download the project source An Intro to GAE 5 / 30
  17. 17. A Simple Glance Say Hello To The World An Unfinished Blog System Limitations Thread and crontab are forbidden Limited socket feature Limitation of resources(CPU, memory, bandwidth...) No access to the filesystem Data can only be exported as csv file No way to download the project source The Great Fire Wall An Intro to GAE 5 / 30
  18. 18. A Simple Glance Say Hello To The World An Unfinished Blog System Limitations Thread and crontab are forbidden Limited socket feature Limitation of resources(CPU, memory, bandwidth...) No access to the filesystem Data can only be exported as csv file No way to download the project source The Great Fire Wall Hidden in Google’s cloud An Intro to GAE 5 / 30
  19. 19. A Simple Glance Say Hello To The World An Unfinished Blog System Applications Quotas An Intro to GAE 6 / 30
  20. 20. A Simple Glance Say Hello To The World An Unfinished Blog System Outline 1 A Simple Glance 2 Say Hello To The World The YAML File The Request Handler The Testing Server Deploying Your Applications 3 An Unfinished Blog System An Intro to GAE 7 / 30
  21. 21. A Simple Glance Say Hello To The World An Unfinished Blog System What is YAML YAML means YAML Ain’t Markup Language A data serialization standard An Intro to GAE 8 / 30
  22. 22. A Simple Glance Say Hello To The World An Unfinished Blog System What is YAML YAML means YAML Ain’t Markup Language A data serialization standard Used as configure file in GAE An Intro to GAE 8 / 30
  23. 23. A Simple Glance Say Hello To The World An Unfinished Blog System What is YAML YAML means YAML Ain’t Markup Language A data serialization standard Used as configure file in GAE Specify the handlers, skipping list and etc. An Intro to GAE 8 / 30
  24. 24. A Simple Glance Say Hello To The World An Unfinished Blog System A Simple YAML File application: myapp version: 1 runtime: python api_version: 1 handlers: - url: / script: home.py handlers: - url: /profile/(.*?)/(.*) script: /employee/2/1.py - url: /stylesheets static_dir: stylesheets - url: /.* script: not_found.py An Intro to GAE 9 / 30
  25. 25. A Simple Glance Say Hello To The World An Unfinished Blog System Handle the Request Handle the request from web An Intro to GAE 10 / 30
  26. 26. A Simple Glance Say Hello To The World An Unfinished Blog System Handle the Request Handle the request from web Define it in app.yaml file is the simplest way But can handle the GET request only An Intro to GAE 10 / 30
  27. 27. A Simple Glance Say Hello To The World An Unfinished Blog System Handle the Request Handle the request from web Define it in app.yaml file is the simplest way But can handle the GET request only webapp is a more powerfull framework And can handle more HTTP actions. An Intro to GAE 10 / 30
  28. 28. A Simple Glance Say Hello To The World An Unfinished Blog System Handle the Request with YAML File Add those lines to app.yaml handlers: - url: /hello script: hello.py An Intro to GAE 11 / 30
  29. 29. A Simple Glance Say Hello To The World An Unfinished Blog System Handle the Request with YAML File Add those lines to app.yaml handlers: - url: /hello script: hello.py Create a hello.py with the lines below print 'Content-Type: text/plain' print '' print 'Hello, world!' An Intro to GAE 11 / 30
  30. 30. A Simple Glance Say Hello To The World An Unfinished Blog System Handle the Request with YAML File Add those lines to app.yaml handlers: - url: /hello script: hello.py Create a hello.py with the lines below print 'Content-Type: text/plain' print '' print 'Hello, world!' Save hello.py in the same dir of app.yaml An Intro to GAE 11 / 30
  31. 31. A Simple Glance Say Hello To The World An Unfinished Blog System Handle Wri en with webapp Framework Config the app.yaml file like before An Intro to GAE 12 / 30
  32. 32. A Simple Glance Say Hello To The World An Unfinished Blog System Handle Wri en with webapp Framework Config the app.yaml file like before Now the improved hello.py shoule be: 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, World!') application = webapp.WSGIApplication( [('/', MainPage)], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main() An Intro to GAE 12 / 30
  33. 33. A Simple Glance Say Hello To The World An Unfinished Blog System What Is The Testing Server Reproduce the GAE runtime An Intro to GAE 13 / 30
  34. 34. A Simple Glance Say Hello To The World An Unfinished Blog System What Is The Testing Server Reproduce the GAE runtime Including the sandbox restrictions An Intro to GAE 13 / 30
  35. 35. A Simple Glance Say Hello To The World An Unfinished Blog System What Is The Testing Server Reproduce the GAE runtime Including the sandbox restrictions Emulating the datastore An Intro to GAE 13 / 30
  36. 36. A Simple Glance Say Hello To The World An Unfinished Blog System What Is The Testing Server Reproduce the GAE runtime Including the sandbox restrictions Emulating the datastore Be able to send email An Intro to GAE 13 / 30
  37. 37. A Simple Glance Say Hello To The World An Unfinished Blog System What Is The Testing Server Reproduce the GAE runtime Including the sandbox restrictions Emulating the datastore Be able to send email Support a development console An Intro to GAE 13 / 30
  38. 38. A Simple Glance Say Hello To The World An Unfinished Blog System Setup the Tesing Server Save your app.yaml into a directory An Intro to GAE 14 / 30
  39. 39. A Simple Glance Say Hello To The World An Unfinished Blog System Setup the Tesing Server Save your app.yaml into a directory Change to its parent directory An Intro to GAE 14 / 30
  40. 40. A Simple Glance Say Hello To The World An Unfinished Blog System Setup the Tesing Server Save your app.yaml into a directory Change to its parent directory Run this command: dev_appserver.py <dir_name> An Intro to GAE 14 / 30
  41. 41. A Simple Glance Say Hello To The World An Unfinished Blog System Setup the Tesing Server Save your app.yaml into a directory Change to its parent directory Run this command: dev_appserver.py <dir_name> Try to connect h p://localhost:8080 An Intro to GAE 14 / 30
  42. 42. A Simple Glance Say Hello To The World An Unfinished Blog System Deploying Your Application Check the app.yaml file The value of application keyword Handlers, static files and etc. An Intro to GAE 15 / 30
  43. 43. A Simple Glance Say Hello To The World An Unfinished Blog System Deploying Your Application Check the app.yaml file The value of application keyword Handlers, static files and etc. Change to the parent director of app.yaml An Intro to GAE 15 / 30
  44. 44. A Simple Glance Say Hello To The World An Unfinished Blog System Deploying Your Application Check the app.yaml file The value of application keyword Handlers, static files and etc. Change to the parent director of app.yaml Run this command: appcfg.py update <dir_name> An Intro to GAE 15 / 30
  45. 45. A Simple Glance Say Hello To The World An Unfinished Blog System Deploying Your Application Check the app.yaml file The value of application keyword Handlers, static files and etc. Change to the parent director of app.yaml Run this command: appcfg.py update <dir_name> Now you can access it via h p://app-id.appspot.com An Intro to GAE 15 / 30
  46. 46. A Simple Glance Say Hello To The World An Unfinished Blog System Dashboard An Intro to GAE 16 / 30
  47. 47. A Simple Glance Say Hello To The World An Unfinished Blog System Logs An Intro to GAE 17 / 30
  48. 48. A Simple Glance Say Hello To The World An Unfinished Blog System Data Viewer An Intro to GAE 18 / 30
  49. 49. A Simple Glance Say Hello To The World An Unfinished Blog System Outline 1 A Simple Glance 2 Say Hello To The World 3 An Unfinished Blog System URL Mapping Database Design Templates Google User Interface On The Way An Intro to GAE 19 / 30
  50. 50. A Simple Glance Say Hello To The World An Unfinished Blog System Some URL Pa ern / index page /article/<id> article detail /post post a article /comment/<id> post a comment /date/<date> filter articles by date /tag/<name> filter articles by tag /login login /logout logout /feed/<key> rss feed An Intro to GAE 20 / 30
  51. 51. A Simple Glance Say Hello To The World An Unfinished Blog System Method Used for Mapping Placed in app.yaml file - url: /blog/.* script: apps/blog/blog.py An Intro to GAE 21 / 30
  52. 52. A Simple Glance Say Hello To The World An Unfinished Blog System Method Used for Mapping Placed in app.yaml file - url: /blog/.* script: apps/blog/blog.py Some configuration in blog.py file application = webapp.WSGIApplication( [(ur'/blog/$' , index_page) , (ur'/blog/article/(.*)' , article_page) , (ur'/blog/post/$' , post_page) , (ur'/blog/category/(.*)' , category_page) ], debug=True) An Intro to GAE 21 / 30
  53. 53. A Simple Glance Say Hello To The World An Unfinished Blog System Database Design Author Info Tags Articles Comments Ariticles_Statics An Intro to GAE 22 / 30
  54. 54. A Simple Glance Say Hello To The World An Unfinished Blog System Database ORM Map a class to a DB table from google.appengine.ext import db class Person(db.Model): An Intro to GAE 23 / 30
  55. 55. A Simple Glance Say Hello To The World An Unfinished Blog System Database ORM Map a class to a DB table Add a data field from google.appengine.ext import db class Person(db.Model): name = db.StringProperty() age = db.IntegerProperty() An Intro to GAE 23 / 30
  56. 56. A Simple Glance Say Hello To The World An Unfinished Blog System Some Samples Insert Bob = Person(name = "Bob", age = 42) Bob.put() An Intro to GAE 24 / 30
  57. 57. A Simple Glance Say Hello To The World An Unfinished Blog System Some Samples Insert Bob = Person(name = "Bob", age = 42) Bob.put() Query query = Person.all().filter(name = "Bob") Bob = query.get() An Intro to GAE 24 / 30
  58. 58. A Simple Glance Say Hello To The World An Unfinished Blog System Some Samples Insert Bob = Person(name = "Bob", age = 42) Bob.put() Query query = Person.all().filter(name = "Bob") Bob = query.get() Modify Bob.age = 43 Bob.put() An Intro to GAE 24 / 30
  59. 59. A Simple Glance Say Hello To The World An Unfinished Blog System Some Samples Insert Bob = Person(name = "Bob", age = 42) Bob.put() Query query = Person.all().filter(name = "Bob") Bob = query.get() Modify Bob.age = 43 Bob.put() Delete Bob.delete() An Intro to GAE 24 / 30
  60. 60. A Simple Glance Say Hello To The World An Unfinished Blog System Templates System No embedded code in HTML files An Intro to GAE 25 / 30
  61. 61. A Simple Glance Say Hello To The World An Unfinished Blog System Templates System No embedded code in HTML files The data was processed in the python file An Intro to GAE 25 / 30
  62. 62. A Simple Glance Say Hello To The World An Unfinished Blog System Templates System No embedded code in HTML files The data was processed in the python file And the HTML just simply display it An Intro to GAE 25 / 30
  63. 63. A Simple Glance Say Hello To The World An Unfinished Blog System Templates System No embedded code in HTML files The data was processed in the python file And the HTML just simply display it The same to the template system in Django An Intro to GAE 25 / 30
  64. 64. A Simple Glance Say Hello To The World An Unfinished Blog System Compare This Two Code Segments <body> <?php <body> <table><tr> <table><tr> for ($i = 0; $i <= 2; $i++) { {% for i in foobar %} print "<td>" . $i . "</td>"; <td>{{ i }}</td> } {% endfor %} ?> </tr></table> </tr></table> </body> </body> An Intro to GAE 26 / 30
  65. 65. A Simple Glance Say Hello To The World An Unfinished Blog System Google User Interface Login with google id and passwd An Intro to GAE 27 / 30
  66. 66. A Simple Glance Say Hello To The World An Unfinished Blog System Google User Interface Login with google id and passwd Can be saved in datastore as UserProperty type An Intro to GAE 27 / 30
  67. 67. A Simple Glance Say Hello To The World An Unfinished Blog System Google User Interface Login with google id and passwd Can be saved in datastore as UserProperty type Used to record and filter the user An Intro to GAE 27 / 30
  68. 68. A Simple Glance Say Hello To The World An Unfinished Blog System On The Way Ajax frontend Play with some other google APIs Multi-author blog Support xml-rpc API interface To be continued· · · An Intro to GAE 28 / 30
  69. 69. A Simple Glance Say Hello To The World An Unfinished Blog System Q and A An Intro to GAE 29 / 30
  70. 70. A Simple Glance Say Hello To The World An Unfinished Blog System Thanks An Intro to GAE 30 / 30

×