20081012 gae intro

Post on 08-May-2015

991 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

An Intro to GAE

Hu Zi Minghzmangel@gmail.com

Oct 12, 2008

.

.

.

.

1 / 30

.

An Intro to GAE

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Outline

.

. .1 A Simple Glance

What is GAEBenefits And Limitations

.

. .

2 Say Hello To The World

.

. .

3 An Unfinished Blog System

.

.

.

.

2 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

3 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

3 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

3 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

3 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

4 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

4 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

4 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

4 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

5 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

5 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

5 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

5 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

5 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

5 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

5 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

5 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Applications Quotas

.

.

.

.

6 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Outline

.

. .1 A Simple Glance

.

. .

2 Say Hello To The WorldThe YAML FileThe Request HandlerThe Testing ServerDeploying Your Applications

.

. .

3 An Unfinished Blog System

.

.

.

.

7 / 30

.

An Intro to GAE

.

.

.

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.

.

.

.

.

8 / 30

.

An Intro to GAE

.

.

.

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.

.

.

.

.

8 / 30

.

An Intro to GAE

.

.

.

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.

.

.

.

.

8 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

A Simple YAML File

application: myappversion: 1runtime: pythonapi_version: 1

handlers:- url: /

script: home.py

handlers:- url: /profile/(.*?)/(.*)

script: /employee/\2/\1.py

- url: /stylesheetsstatic_dir: stylesheets

- url: /.*script: not_found.py

.

.

.

.

9 / 30

.

An Intro to GAE

.

.

.

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.

.

.

.

.

10 / 30

.

An Intro to GAE

.

.

.

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.

.

.

.

.

10 / 30

.

An Intro to GAE

.

.

.

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.

.

.

.

.

10 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Handle the Request with YAML File

Add those lines to app.yamlhandlers:- url: /hello

script: hello.py

Create a hello.py with the lines belowprint 'Content-Type: text/plain'print ''print 'Hello, world!'

Save hello.py in the same dir of app.yaml

.

.

.

.

11 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Handle the Request with YAML File

Add those lines to app.yamlhandlers:- url: /hello

script: hello.py

Create a hello.py with the lines belowprint 'Content-Type: text/plain'print ''print 'Hello, world!'

Save hello.py in the same dir of app.yaml

.

.

.

.

11 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Handle the Request with YAML File

Add those lines to app.yamlhandlers:- url: /hello

script: hello.py

Create a hello.py with the lines belowprint 'Content-Type: text/plain'print ''print 'Hello, world!'

Save hello.py in the same dir of app.yaml

.

.

.

.

11 / 30

.

An Intro to GAE

.

.

.

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 webappfrom 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()

.

.

.

.

12 / 30

.

An Intro to GAE

.

.

.

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 webappfrom 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()

.

.

.

.

12 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

13 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

13 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

13 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

13 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

13 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

14 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

14 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

14 / 30

.

An Intro to GAE

.

.

.

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

.

.

.

.

14 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Deploying Your Application

Check the app.yaml fileThe value of application keywordHandlers, 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

.

.

.

.

15 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Deploying Your Application

Check the app.yaml fileThe value of application keywordHandlers, 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

.

.

.

.

15 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Deploying Your Application

Check the app.yaml fileThe value of application keywordHandlers, 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

.

.

.

.

15 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Deploying Your Application

Check the app.yaml fileThe value of application keywordHandlers, 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

.

.

.

.

15 / 30

.

An Intro to GAE

.

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Dashboard

.

.

.

.

16 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Logs

.

.

.

.

17 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Data Viewer

.

.

.

.

18 / 30

.

An Intro to GAE .

.

.

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 SystemURL MappingDatabase DesignTemplatesGoogle User InterfaceOn The Way

.

.

.

.

19 / 30

.

An Intro to GAE .

.

.

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

.

.

.

.

20 / 30

.

An Intro to GAE .

.

.

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 fileapplication = webapp.WSGIApplication(

[(ur'/blog/$' , index_page) ,(ur'/blog/article/(.*)' , article_page) ,(ur'/blog/post/$' , post_page) ,(ur'/blog/category/(.*)' , category_page) ], debug=True)

.

.

.

.

21 / 30

.

An Intro to GAE .

.

.

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 fileapplication = webapp.WSGIApplication(

[(ur'/blog/$' , index_page) ,(ur'/blog/article/(.*)' , article_page) ,(ur'/blog/post/$' , post_page) ,(ur'/blog/category/(.*)' , category_page) ], debug=True)

.

.

.

.

21 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Database Design

Author Info

Tags

Articles

Comments

Ariticles_Statics

.

.

.

.

22 / 30

.

An Intro to GAE .

.

.

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 dbclass Person(db.Model):

name = db.StringProperty()age = db.IntegerProperty()

.

.

.

.

23 / 30

.

An Intro to GAE .

.

.

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 dbclass Person(db.Model):

name = db.StringProperty()age = db.IntegerProperty()

.

.

.

.

23 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Some Samples

InsertBob = Person(name = "Bob", age = 42)Bob.put()

Queryquery = Person.all().filter(name = "Bob")Bob = query.get()

ModifyBob.age = 43Bob.put()

DeleteBob.delete()

.

.

.

.

24 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Some Samples

InsertBob = Person(name = "Bob", age = 42)Bob.put()

Queryquery = Person.all().filter(name = "Bob")Bob = query.get()

ModifyBob.age = 43Bob.put()

DeleteBob.delete()

.

.

.

.

24 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Some Samples

InsertBob = Person(name = "Bob", age = 42)Bob.put()

Queryquery = Person.all().filter(name = "Bob")Bob = query.get()

ModifyBob.age = 43Bob.put()

DeleteBob.delete()

.

.

.

.

24 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Some Samples

InsertBob = Person(name = "Bob", age = 42)Bob.put()

Queryquery = Person.all().filter(name = "Bob")Bob = query.get()

ModifyBob.age = 43Bob.put()

DeleteBob.delete()

.

.

.

.

24 / 30

.

An Intro to GAE .

.

.

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

.

.

.

.

25 / 30

.

An Intro to GAE .

.

.

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

.

.

.

.

25 / 30

.

An Intro to GAE .

.

.

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

.

.

.

.

25 / 30

.

An Intro to GAE .

.

.

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

.

.

.

.

25 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Compare This Two Code Segments

<body><?php<table><tr>

for ($i = 0; $i <= 2; $i++) {print "<td>" . $i . "</td>";}?></tr></table>

</body>

<body><table><tr>{% for i in foobar %}

<td>{{ i }}</td>{% endfor %}</tr></table>

</body>

.

.

.

.

26 / 30

.

An Intro to GAE .

.

.

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

.

.

.

.

27 / 30

.

An Intro to GAE .

.

.

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

.

.

.

.

27 / 30

.

An Intro to GAE .

.

.

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

.

.

.

.

27 / 30

.

An Intro to GAE .

.

.

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· · ·

.

.

.

.

28 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Q and A

.

.

.

.

29 / 30

.

An Intro to GAE .

.

.

A Simple Glance

.

.

Say Hello To The World

.

.

An Unfinished Blog System

Thanks

.

.

.

.

30 / 30

.

An Intro to GAE .

top related