可以讓你在 Google 上面運行你的網頁程式. 可以使用免費的網域名 appspot.com 或是透過 Google Apps 來使用自己的網域名稱.
目前只能用 Python
來寫 GAE 程式.
本範例會做出一個簡單的 Guest book, 讓使用者可以在上面發表一個公開的留言, 使用者還可以使用匿名或是 Google 帳號來發表. 透過這個範例可以學習到:
The Development Environment
開發與上傳 Google App Engine 必須要安裝
在範例中會使用到兩個 SDK 的指令
Hello, World!
建一個目錄取名 helloworld. 在這個目錄裡面建一個檔案 helloworld.py, 內容是:
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
每個 App Engine 程式都有一個設定檔案叫 app.yaml. 裡面會描述如何處理網頁的請求.
現在在 helloworld 目錄裡面再建立一個 app.yaml, 內容是:
application: helloworld
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: helloworld.py
更詳細的內容請參考 app.yaml reference
接著測試剛剛寫的內容, 在命令列下執行:
google_appengine/dev_appserver.py helloworld/
執行過後, 會開始運行網頁服務, port 8080. 只需要在瀏覽器上輸入
就可以看到效果了. 另外可以使用 Ctrl+C 來關閉. 關於其他的參數請參考 Dev Web Server reference
Using the webapp Framework
Google App Engine 支援各種純 python 寫的 CGI 框架, 包含 Django, CherryPy, PyIons, web.py. 而 App Engine 也內建一個簡單的框架 webapp. 一個 webapp 程式包含了三個部分:
現在重新修改 helloworld/helloworld.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/plain'
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication([('/', MainPage)], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Using the Users Service
TODO: http://code.google.com/appengine/docs/python/gettingstarted/usingusers.html
記錄一些使用上遇到的問題.
No module named _multiprocessing
這個原因可能是 Python 版本問題, 如果是使用 2.6 版本的, 降低版本到 2.5 的就可以解決了.
的 Comment 7, 看到了更好的解決方法, 直接把它提供的 _multiprocessing.py 放在 app root 就可以了.
// code block
@TODO:
-----
Configuring Eclipse on Windows to Use With Google App Engine
http://code.google.com/appengine/articles/eclipse.html
-----
你可以連到 http://localhost:8080/_ah/admin/datastore 檢查資料 (存在你電腦裡)。
-----