Developing_with_Google_App_Engine.pdf

(3439 KB) Pobierz
373142438 UNPDF
373142438.004.png
Contents
Chapter 1: Google App Engine .....................................................1
What Is Google App Engine? ................................................................. 1
Google App Engine and Cloud Computing ........................................... 2
End User Applications on the Cloud............................................................. 2
Services on the Cloud.................................................................................... 2
Google App Engine and the Cloud ............................................................... 3
Before You Start Using App Engine ...................................................... 3
Setting Up Your Development Environment ......................................... 4
Hello, World!........................................................................................... 6
Summary.................................................................................................. 8
Chapter 2: Exploring the SDK.....................................................11
Creating Your First Complete Project ................................................. 11
The webapp Framework .............................................................................. 14
Using the Sandboxed Python Runtime ................................................ 15
Putting the Application Together ......................................................... 17
Using Templates vs. Inline HTML ............................................................. 20
Deciding How Many Event Handlers .................................................. 20
Debugging the Application ................................................................... 21
Debugging Options for the Development Web Server ............................... 22
Debugging a WSGIApplication .................................................................. 22
Implementing a Debugging Aid .................................................................. 23
Developing with Google App Engine
i
373142438.005.png 373142438.006.png
Interactive Debugging ................................................................................. 27
Publishing to the Web ........................................................................... 27
Creating and Registering an Application .................................................... 28
Uploading an Application ........................................................................... 29
Running an Application from a Custom Domain ....................................... 30
Summary................................................................................................ 32
Chapter 3: The Design of a Google App Engine Application ..........33
The BookmarksBin Application ........................................................... 33
The Data Model..................................................................................... 33
Wait, No User Table? .................................................................................. 35
Web Application Architecture .............................................................. 35
Pages-to-Components Mapping .................................................................. 38
Summary................................................................................................ 39
Chapter 4: Building an Application..............................................41
Working with the webapp Framework ................................................. 41
Working With Other Frameworks........................................................ 43
Laying Out Applications with webapp Templates ............................... 44
Exploring the Template Hierarchy .............................................................. 45
Assembling the Templates and Handlers .................................................... 46
Using Static Files .................................................................................. 51
Displaying a Favicon................................................................................... 53
Beautifying Your User Interface with CSS................................................. 55
Downloading the Source Files for the Examples ........................................ 56
Summary................................................................................................ 56
ii
Developing with Google App Engine
 
373142438.001.png
Chapter 5: What About the Users? .............................................57
Authentication and Google Accounts .................................................. 58
Using GData Services ................................................................................. 59
User Objects........................................................................................... 60
What About Specific Domains? .................................................................. 61
Getting a Valid User Object and the Users API.......................................... 62
Other Users API Functions ......................................................................... 65
User Objects in the Datastore ............................................................... 65
Configuring Admin Users..................................................................... 68
Defining Admin Users................................................................................. 68
Validating Admin Users in the Code .......................................................... 69
Summary................................................................................................ 72
Chapter 6: Using the Datastore..................................................73
Bigtable and the Datastore ................................................................... 73
The Datastore API ................................................................................ 75
Entities and Unique Identifiers.................................................................... 75
Disallowed Property Names........................................................................ 78
Entity Groups and Transactions .................................................................. 79
Implementing Persistence for the BookmarksBin Application .......... 79
Persisting and Querying an Entity............................................................... 80
Deciding Which Calls to the Datastore Are Necessary............................... 87
Associating and Manipulating Entities................................................ 87
One-to-Many Relationships ........................................................................ 88
Choosing Between Query and GqlQuery.................................................... 92
The Google Query Language ............................................................... 93
Specifying Conditional Clauses .................................................................. 94
Developing with Google App Engine
iii
 
373142438.002.png
Indexing Entities in the Datastore ....................................................... 95
Automatic Indexing and Queries................................................................. 96
Defining Indexes Manually ......................................................................... 97
Indexes That Are Not Created by App Engine ........................................... 99
Restrictions on Queries ............................................................................... 99
Committing Data in Transactions ...................................................... 100
Reasons for Using Transactions ................................................................ 101
Using the Transaction API ........................................................................ 102
Many-to-Many Relationships.................................................................... 103
Storing and Deleting Entities .................................................................... 105
Summary.............................................................................................. 109
Chapter 7: Memcache and Session Data ................................... 111
What Is Memcache?............................................................................ 111
Using Memcache for Session Data .................................................... 114
Caching the Session Owner....................................................................... 114
Implementing Memcache Calls with Entities ........................................... 116
Defining Unique Key Names .................................................................... 117
Using Memcache Services Throughout an Application.................... 118
Caching Data from Complex Queries ....................................................... 119
Invalidating the Cache............................................................................... 121
Other Memcache Functions....................................................................... 121
Summary.............................................................................................. 121
Chapter 8: Mail, URL Fetching, and Image Manipulation............. 123
Sending E-mail.................................................................................... 123
Configuring dev_appserver.py .................................................................. 123
Configuring the App Engine to Send Mail................................................ 125
Sending E-mail From an Application........................................................ 125
Using E-mail Templates............................................................................ 128
iv
Developing with Google App Engine
 
373142438.003.png
Zgłoś jeśli naruszono regulamin